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.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
