Skip to main content
To create a sudo user on Ubuntu, run sudo adduser alex and then sudo usermod -aG sudo alex. Debian works the same way. On AlmaLinux and Rocky Linux the admin group is wheel: run sudo useradd -m alex, sudo passwd alex and sudo usermod -aG wheel alex. Log in as the new user and run sudo whoami; it prints root.

Before you start

  • Connect with SSH as root (or an existing sudo user). As root you can leave sudo out of the commands below.
  • Choose a user name in lower case, for example alex.

Why use a sudo user instead of root?

root can do anything, with no confirmation. A normal user with sudo rights works without admin power and only becomes root for one command at a time when you type sudo. Mistakes are less likely, every sudo command is logged, and you can later disable root login over SSH.

How to create a sudo user

1

Create the user

Enter a strong password twice. The name and phone fields are optional: press Enter to skip them, then Y. adduser creates the home directory /home/alex for you.
2

Add the user to the sudo group

-a (append) is important. Without it, -G replaces all the user’s other groups.
3

Check the groups

Expected output:
Some minimal Debian installs don’t include sudo. If you see sudo: command not found, install it as root first: apt install sudo.

How to let the new user log in with your SSH key

If you log in to root with an SSH key, copy the key to the new user so you can log in without a password. Run as root:
The strict permissions matter: SSH ignores an authorized_keys file that other users can write to.

How to check it worked

Keep your current root session open. Test the new user in a second terminal before you log out or change any SSH settings, so you can fix mistakes if the login fails. If you get locked out of a VPS, use the VNC console.
1

Log in as the new user

2

Test sudo

Enter alex’s password (not root’s). Expected output:
sudo -l lists what the user is allowed to run. For a full admin it shows (ALL : ALL) ALL.

How to give sudo without a password (optional)

For automation accounts you can allow sudo without a password. Always edit sudo rules with visudo, which checks the syntax before saving; a broken sudoers file can stop every user from using sudo.
Add this line, save and exit:
File names in /etc/sudoers.d/ must not contain a dot or end with ~, or sudo ignores them. Check all files with sudo visudo -c.
Passwordless sudo means anyone who gets into that account is instantly root. Use it only for accounts that log in with SSH keys.

Frequently asked questions

What is the difference between adduser and useradd?

On Ubuntu and Debian, adduser is a friendly script that asks for a password and creates the home directory. useradd is the low-level tool on every distribution; it needs options such as -m for the home directory and a separate passwd command. On AlmaLinux and Rocky, adduser is the same as useradd.

Why does sudo say “alex is not in the sudoers file”?

The user is not in the sudo group (Ubuntu/Debian) or wheel group (AlmaLinux/Rocky), or you haven’t logged in again since adding them. Group changes apply at the next login.

How do I remove sudo rights from a user?

Run sudo gpasswd -d alex sudo on Ubuntu/Debian or sudo gpasswd -d alex wheel on AlmaLinux/Rocky, and delete any file for that user in /etc/sudoers.d/.

Can I log in to my VPS as root after this?

Yes, until you turn it off. Once your sudo user works, you can disable root login over SSH. Keep a way back in: the VPS Panel can reset the root password.

VPS and dedicated server guides

Every server guide in one place.

Manage users and groups

Add, change and remove users.

Create and use SSH keys

Log in without passwords.

Disable root login over SSH

The next hardening step.

Fix sudo errors

When sudo doesn’t work.

Checked against the official Red Hat Enterprise Linux 9 documentation on managing sudo access and the adduser, usermod and sudoers man pages on 4 November 2026; Ubuntu/Debian commands tested on Ubuntu 24.04 LTS. Commands can differ on other distributions or releases.

Need Extra Help?

If you encounter any issues, our support team is ready to assist:

Save on Your Hosting

Ready to upgrade your hosting? Use code KB20 at checkout for 20% off your first order!

Last Updated: November 2026