NetPoa

Create a sudo user and sign in with an SSH key

Updated 27 Nov 2026

Signing in as root with a password is the easiest way into your server for attackers. A personal user with sudo and an SSH key is much safer, and you can see who did what. This guide goes deeper than Secure a new Cloud VPS in 10 minutes, including a common Ubuntu setting that silently keeps passwords switched on.

Replace asha with your own user name and 102.214.10.25 with your server's IPv4 address.

1. Create the user

Sign in as root, then:

adduser asha
usermod -aG sudo asha

adduser asks for a password. Choose a strong one: you'll still need it when you run sudo.

Check the user is in the sudo group:

groups asha

2. Add your SSH key

On your own computer, make a key if you don't have one:

ssh-keygen -t ed25519

Then copy it to the server:

ssh-copy-id asha@102.214.10.25

On Windows PowerShell, where ssh-copy-id isn't available:

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh asha@102.214.10.25 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Already sign in to root with a key? Copy root's keys to the new user instead. Run this on the server as root:

rsync --archive --chown=asha:asha ~/.ssh /home/asha

3. Test the key and sudo

From your computer:

ssh asha@102.214.10.25
sudo whoami

It should sign you in without the server password, and sudo whoami should print root after you type your user's password.

Don't go on until this works. The next step turns off passwords. If your key doesn't work, you'll be locked out.

4. Turn off password and root sign-in

Ubuntu reads extra SSH settings from the folder /etc/ssh/sshd_config.d/, and the first value it finds wins. Cloud servers often have a file there that sets PasswordAuthentication yes. So put your settings in a file that's read first:

sudo nano /etc/ssh/sshd_config.d/00-hardening.conf

Add:

PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no

Save with Ctrl+O, Enter, Ctrl+X. Then check for mistakes and see the settings SSH will really use:

sudo sshd -t
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication|kbdinteractive'

You should see permitrootlogin no, passwordauthentication no and kbdinteractiveauthentication no. If not, look for other files that set them:

sudo grep -ri 'passwordauthentication' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/

5. Restart SSH and test

sudo systemctl restart ssh

Keep your current window open. In a new window, check:

ssh asha@102.214.10.25
ssh root@102.214.10.25

The first should work. The second should be refused. Only then close the old window.

Keep your key safe

  • Your private key is ~/.ssh/id_ed25519 on your computer. Never send it to anyone or copy it to the server.
  • Back it up somewhere safe, or add a second key from another computer to ~/.ssh/authorized_keys on the server.
  • If you lose every key, open a ticket and choose Technical. Reset root password in the portal won't help on its own, because password sign-in is now off.

Need a server? Order a Cloud VPS and get root access within minutes. For help, open a ticket and choose Technical.

Was this helpful?