−25%

on annual Windows plans, until 31 Oct. See plans

EQVPS

How to create a sudo user on a VPS and stop using root

Create a non-root sudo user on Ubuntu or Debian, give it your SSH key, test it, then switch off root login — in an order that can't lock you out.

Almost every new VPS starts the same way: you log in as root, install a few things, and a month later you're still root. It works right up until a script you pasted deletes the wrong directory. Setting up a normal user with sudo takes five minutes, and the order matters more than the commands — do it wrong and you lock yourself out.

Here's the safe sequence for Ubuntu 22.04/24.04 and Debian 12.

1. Create the user

As root:

adduser deploy
usermod -aG sudo deploy

adduser asks for a password and some optional details (just press Enter through those). Pick a real password: you'll type it for sudo. On a minimal Debian image, run apt install -y sudo first if the command is missing.

2. Give it your SSH key

The easiest way is to copy root's authorized keys, keeping ownership right:

rsync --archive --chown=deploy:deploy /root/.ssh /home/deploy

If you prefer to do it by hand:

mkdir -p /home/deploy/.ssh
cp /root/.ssh/authorized_keys /home/deploy/.ssh/
chown -R deploy:deploy /home/deploy/.ssh
chmod 700 /home/deploy/.ssh
chmod 600 /home/deploy/.ssh/authorized_keys

Wrong permissions are the classic reason key login silently fails. SSH ignores an authorized_keys that other users can write to.

3. Test before you change anything

Keep your root session open. In a new terminal:

ssh -p 22 deploy@203.0.113.10
sudo whoami

Use your own IP and port — on a NAT plan that's your personal SSH port from the dashboard. If sudo whoami prints root, you're good. If the login fails, you still have the root window to fix it.

4. Turn off root login

Now close the door. Create a small drop-in file instead of editing the main config:

cat > /etc/ssh/sshd_config.d/10-hardening.conf <<'EOF'
PermitRootLogin no
PasswordAuthentication no
EOF
sshd -t && systemctl reload ssh

sshd -t checks the syntax first. A broken config plus a reload is how people end up needing the console. PasswordAuthentication no only makes sense once key login works for your new user — which you just tested.

Open one more terminal and confirm root is refused and deploy still gets in. Then close the old root session.

5. Optional: passwordless sudo for automation

If a deploy script needs sudo without a prompt, give it exactly that and nothing wider:

visudo -f /etc/sudoers.d/deploy
deploy ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart myapp

Honestly, NOPASSWD: ALL is tempting, but it means a stolen key equals root. Limit it to the commands the automation runs.

If something goes wrong

The web console in your dashboard doesn't depend on SSH or the firewall. Log in there, fix the file in /etc/ssh/sshd_config.d/, reload, done. We wrote up the full recovery flow in how to get back into a locked-out VPS.

What to do next

Access options for every plan are in the access docs. Even a $3 Nano deserves a non-root user — it's the cheapest security upgrade there is.

FAQ

Why not just keep using root?

Everything you run as root can break the whole system, including a typo. Bots also try the username 'root' first, so disabling root login removes the most-guessed target. A named user plus sudo gives you a pause before every privileged command and a log of what was run.

What if I lock myself out?

Use the web console in your dashboard. It works even when SSH is broken or the firewall blocks you, so you can log in and fix sshd_config. That's also why you test the new user before closing your root session.

Should I allow sudo without a password?

For a human account, keep the password prompt — it's a last line of defence if your SSH key leaks. Passwordless sudo is reasonable for a dedicated deploy user used by automation, limited to the commands it actually needs.

The sudo command doesn't exist on my Debian server. Why?

Minimal Debian images don't always ship it. Install it as root with 'apt install -y sudo', then add your user to the sudo group.

Which SSH port do I use?

The one shown in your dashboard. Dedicated-IP plans use port 22 on your own IP; NAT plans use your personal SSH port.

Comments

No comments yet. Be the first.

Leave a comment

Comments are moderated before they appear.