Operations 5 min read
Secure Linux: Disable Root SSH Login and Set Up a Sudo User
This guide walks you through creating a non‑root sudo user, configuring its password and group, disabling root SSH access by editing sshd_config, and restarting the service, ensuring secure remote login on Linux systems.
MaGe Linux Operations
MaGe Linux Operations
Background
For security reasons, root login via SSH should be disabled.
After disabling root SSH login, a privileged user is needed for remote access.
Create a User with Sudo Privileges
Create a regular user "rain"
useradd command creates a user; -m creates a home directory, -c adds a comment.
useradd -m -c "Normal User" rainSet a password for the user "rain"
Note: Password should be at least 8 characters, include upper and lower case letters, numbers, special symbols, and must not contain the username.
passwd rainAdd the user "rain" to the administrative group
usermod modifies user settings; -G specifies groups to add, and omitting -a removes the user from groups not listed.
In CentOS/RHEL the wheel group has sudo rights; in Debian/Ubuntu the sudo group does.
usermod -aG wheel rainDisable Root SSH Login
Switch to the privileged user "rain"
After creating a user with administrative rights, switch to it to prevent root SSH login.
su rainEdit the sshd_config file
Although the file can be edited directly with root, using the privileged account (rain) ensures the account already has sudo rights.
sudo vi /etc/ssh/sshd_configSet the PermitRootLogin parameter to no .
PermitRootLogin noRestart the sshd service
After saving the file, restart the sshd service to apply changes.
On older Linux versions the command may be sudo service sshd restart .
sudo systemctl restart sshdTest the root SSH login
The login attempt should fail with the same result as an incorrect password.
Original Source
Signed-in readers can open the original source through BestHub's protected redirect.
Republication Notice
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Reader feedback
How this landed with the community
Rate this article
Was this worth your time?
Discussion
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
