Operations 5 min read

How to Secure Linux: Create a Sudo User and Disable Root SSH Login

This guide explains why disabling root SSH access is essential, then walks through creating a privileged user, assigning sudo rights, editing the sshd_config file to reject root logins, restarting the service, and verifying that root login is effectively blocked.

Raymond Ops
Raymond Ops
Raymond Ops
How to Secure Linux: Create a Sudo User and Disable Root SSH Login

Background

For security reasons, root login via SSH should be prohibited.

After disabling root SSH login, a privileged user is needed for remote access.

Create a user with sudo privileges

Create a normal user "rain"

Create user rain
Create user rain
useradd command creates a user; -m creates a home directory, -c adds a comment.
useradd -m -c "Normal User" rain

Set a password for the user

Set password for rain
Set password for rain
Password should be at least 8 characters, include upper‑ and lower‑case letters, numbers, special symbols, and must not contain the username.
passwd rain

Add the user to the admin group

Add rain to wheel group
Add rain to wheel group
usermod modifies user settings; -aG appends the user to a group. On CentOS/RHEL the wheel group has sudo rights, while on Debian/Ubuntu the sudo group does.
usermod -aG wheel rain

Disable root SSH login

Switch to the privileged user

Switch to rain
Switch to rain
su rain

Edit the sshd_config file

Edit sshd_config
Edit sshd_config
Even though root can edit the file, using the sudo‑enabled user ensures the changes are made with proper privileges.
sudo vi /etc/ssh/sshd_config
Set PermitRootLogin to no
Set PermitRootLogin to no
Set PermitRootLogin to no .
PermitRootLogin no

Restart the SSH service

Restart sshd
Restart sshd
After saving the file, restart the service to apply changes. Older systems may use sudo service sshd restart .
sudo systemctl restart sshd

Test root login

Root login test
Root login test
The login attempt fails with the same response as an incorrect password, confirming that root SSH access is disabled.
LinuxsecuritySudoroot login
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.