How to Create Sudo Users and Disable Root Login on a New VPS
To create sudo users and lock down a new VPS, add a normal user, give it sudo rights, set up SSH key login for that user, test that sudo works, and only then disable root login. The order matters: disabling root before the new user works locks you out of your own server. This guide follows the safe order, with the test step that catches mistakes while root still works.
Root is the account attackers target because it can do everything and its name never changes. A brute force attack against root needs only a password, while an attack against a named user needs both the name and the password. Moving daily work to a named sudo user removes the easiest target and leaves a clear audit trail of who ran each admin command. For the wider first-week routine, see our first 10 things to do after buying a VPS, which puts this step next to firewall and update tasks.
Create Sudo Users the Safe Way on Ubuntu
Log in as root, then create the user with a home folder and a shell:
adduser deploy
The command asks for a password and basic details. Use a strong password even though you plan to use SSH keys, because the password is a fallback and a sudo prompt still asks for it. Then add the user to the sudo group:
usermod -aG sudo deploy
The -aG flags append the group without removing existing groups, which is the detail that matters: usermod -G sudo without -a would replace the group list and drop groups the user already had. Confirm the groups with id deploy and confirm sudo works before you go further by switching to the user and running sudo -l and sudo whoami, which should print root. That check proves the sudo user permissions are correct before you touch SSH settings.
Set Up SSH Key Authentication for the New User
SSH key login replaces a password that can be guessed with a key pair that cannot. This ssh key authentication vps setup is the step that makes password guessing useless. From your own machine, generate a key if you do not have one:
ssh-keygen -t ed25519 -C "deploy-vps"
Then copy the public key to the new user on the server:
ssh-copy-id deploy@your-server-ip
If ssh-copy-id is not available, create the folder and file by hand on the server as the new user: mkdir -p ~/.ssh && chmod 700 ~/.ssh, add the public key line to ~/.ssh/authorized_keys, then chmod 600 ~/.ssh/authorized_keys. Wrong permissions are the most common cause of key login failing: SSH ignores an authorized_keys file that other users can write, so the chmod steps are part of the setup, not decoration. Our SSH keys setup guide covers key types and agent use in more depth.
Test Sudo and SSH Key Login Before You Disable Root
Open a new terminal and log in as the new user with the key:
ssh -i ~/.ssh/id_ed25519 deploy@your-server-ip
Confirm you land without a password prompt, then run sudo apt update and confirm it asks for the user password once and then runs. Keep the original root session open in the other terminal while you test. If the new login fails, the open root session is your way back in to fix permissions or the authorized_keys file. Only close it after the new login and sudo both pass. This two-terminal habit prevents the most common lockout, and it costs nothing.
Also test from the exact machine and network you will use daily, not just from the machine you set the key up on. A key stored only on one laptop is a single point of failure, so keep a backup of the private key in a safe place, such as an encrypted store, before you rely on it as the only way in.
Disable Root SSH Login in sshd_config
With the new user proven, edit the SSH daemon config. To disable root ssh login, set the option below and nothing else in that step. Open /etc/ssh/sshd_config and set:
PermitRootLogin no
While you are there, consider setting PasswordAuthentication no to require keys for all users, which closes password guessing entirely. That step is safe only after every user who needs access has a working key, so check that first. After editing, test the config with sudo sshd -t, then restart the daemon:
sudo systemctl restart ssh
On some systems the service is named sshd instead of ssh, so use the name that systemctl status ssh or systemctl status sshd shows as active. Verify the change by trying to log in as root from a new terminal: it should fail at once, while the sudo user login still works. If root still logs in, another config file under /etc/ssh/sshd_config.d/ may override your setting, and you should search that folder for a second PermitRootLogin line.
Disable Root Login Fully with Sudo and Fail2ban Layers
Disabling root SSH login stops remote root access, but root still exists locally, and a sudo user can still become root with sudo -i. That is by design: sudo users need a path to admin work. The security gain is the audit trail and the extra step, not the removal of root itself. For servers where even local root login should be off, lock the root password with sudo passwd -l root, which keeps root usable through sudo while blocking direct password login. Do not delete the root account or its home, because system services and recovery paths expect it to exist.
Add Fail2ban as the next layer, so repeated failed logins against any user get blocked at the firewall. Our Fail2ban setup guide covers the SSH jail, and our guide to disabling password login extends the key-only idea to every account. Together, a named sudo user, key-only login, disabled root SSH, and Fail2ban turn the login path from the weakest part of a new VPS into one of the strongest.
Common Mistakes When You Disable Root Login
The classic mistake is disabling root before testing the new user, which locks you out and forces a provider console rescue. The second is a permissions mistake on .ssh or authorized_keys that silently rejects the key, which the open root session would have caught. The third is editing the wrong config file, such as a client config instead of the daemon config, so the change never applies. The fourth is forgetting a second admin or a deploy script that logs in as root, which breaks the next deploy and tempts someone to re-enable root in a hurry. List every login path before you change the config, and update each one to the new user.
Keep a recovery plan. Know how your provider console access works, keep a tested key backup, and document the sudo username somewhere safe. A server you cannot log into is no more useful than a server an attacker controls, and the difference between the two is a tested login and a backup key.