How to Disable Root Login and Use a Regular User with Sudo Access Print

  • sudo, ssh
  • 0

For better security, it’s recommended to disable direct root login over SSH and use a regular user with sudo privileges instead. This helps protect your server from brute-force attacks on the root account.

 

This guide will walk you through creating a new user, granting them sudo access, and disabling root SSH login.

 


 

Step 1: Log in to Your VPS as Root

 

Use SSH to connect to your server:

ssh root@your_server_ip

 

 


 

Step 2: Create a New User

 

Replace newuser with the username you want to create:

adduser newuser

You’ll be asked to set a password and provide optional information. Only the password is required.

 


 

Step 3: Grant Sudo Access to the New User

 

Run the following command to add the user to the sudo group:

usermod -aG sudo newuser

Now the user can run commands with elevated privileges using sudo.

 


 

Step 4: Test the New User

 

Before disabling root login, open a new SSH session and log in with the new user to verify everything works:

ssh newuser@your_server_ip

Try running a command with sudo to make sure you have admin access:

sudo apt update

If prompted, enter the new user’s password.

 


 

Step 5: Disable Root Login via SSH

 

Once you’ve confirmed the new user works, disable root login.

 

1. Open the SSH config file:

nano /etc/ssh/sshd_config

2. Find the line:

PermitRootLogin yes

Change it to:

PermitRootLogin no

If the line is commented (#), remove the # as well.

 

3. Save and exit:

• Press Ctrl + X, then Y, then Enter to save.

 

4. Restart the SSH service:

 

For Debian/Ubuntu:

systemctl restart ssh

For CentOS/RHEL:

systemctl restart sshd

 

 


 

Step 6: Confirm Root Login is Disabled

 

Now try to log in as root again:

ssh root@your_server_ip

You should see a message like “Permission denied” — this confirms root login is disabled.

 


 

Important Notes

• Always test your new user before disabling root login.

• You can re-enable root login later by editing /etc/ssh/sshd_config again and setting PermitRootLogin yes.

 


 

Conclusion

 

Disabling root login and using a regular user with sudo privileges adds an extra layer of security to your VPS. If you face issues accessing your VPS, you can reset root access using SolusVM or contact Hosteons Support for help.

 


Was this answer helpful?

« Back