bytama

ยท 1 min read

Create a non-root user on a fresh Ubuntu server

Add a sudo user, switch to it, and stop doing everyday work as root over SSH.

A fresh VPS image usually hands you root and nothing else. One typo as root can rewrite the system, and every root SSH session is a session worth stealing. Five minutes of setup fixes that.

1. Add the user

adduser james

adduser asks for a password and creates /home/james. Use a real password even if you plan to log in with keys only: it is also the password sudo will ask for.

2. Add the user to the sudo group

usermod -aG sudo james

-a matters. Without it, -G replaces every supplementary group the account already belongs to.

3. Test before you trust it

su - james
sudo whoami

The first command starts a fresh login shell as the new user. The second should return root after asking for the password from step 1.

Keep the root session open until the new login is proven to work. If something later breaks SSH, you still have a way back in.

Source: HostAdvice โ€” create a non-root user on Ubuntu.