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 leavesudoout 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
- Ubuntu / Debian
- AlmaLinux / Rocky
1
Create the user
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
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:authorized_keys file that other users can write to.
How to check it worked
1
Log in as the new user
2
Test sudo
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 withvisudo, which checks the syntax before saving; a broken sudoers file can stop every user from using sudo.
/etc/sudoers.d/ must not contain a dot or end with ~, or sudo ignores them. Check all files with sudo visudo -c.
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 thesudo 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?
Runsudo 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.Related guides
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:- Live Chat: Quick assistance via our website.
- Support Ticket: Open a Ticket
- Discord: Join our Community
- Email: support@freakhosting.com
Last Updated: November 2026