Creating a new sudo user on Debian
A step-by-step guide to creating a sudo-capable user on Debian, including the Debian-specific gotcha where sudo isn't installed by default.
24 December 2024 3 min read
If you’re coming from Ubuntu, this one catches people out: on a fresh minimal Debian install, the sudo package usually isn’t installed at all. Run sudo as a normal user straight after setup and you’ll just get command not found, or on some installs a permission error, because the command doesn’t exist yet. Here’s how to set up a proper sudo user on Debian from scratch.
1. Log in as root and install sudo
You’ll need to do this part as root, since there’s no sudo yet to use. Log in as root (or via whatever initial account your VPS was provisioned with) and check whether sudo is already present:
which sudo
If that returns nothing, install it:
apt update
apt install sudo
2. Create the new user
Debian’s adduser is a friendlier, interactive wrapper around the lower-level useradd command – it creates a home directory, sets up a default shell, and prompts you for a password and optional details:
adduser yourusername
Follow the prompts to set a password. The full name and other details are optional – you can just press enter through them.
3. Add the user to the sudo group
On Debian, members of the sudo group are granted sudo privileges by default (this is set up in /etc/sudoers via the %sudo group rule when the sudo package is installed). Add your new user to it:
usermod -aG sudo yourusername
The -aG flags matter here – -a appends the group rather than replacing existing group memberships, and -G specifies the group(s) to add. Leaving off -a is a common mistake that strips a user out of every other group they’re in.
4. Verify sudo access
Group membership changes don’t apply to sessions that are already open, so log out and back in as the new user (or start a fresh SSH session):
su - yourusername
Then confirm sudo works:
sudo whoami
You’ll be prompted for the user’s own password (not root’s) the first time, and it should print root. If it does, you’re set.
Why doesn’t Debian just include sudo?
It’s consistent with Debian’s general philosophy of shipping a minimal base and letting you add what you need, rather than pre-installing conveniences you might not want. Ubuntu, by contrast, installs sudo by default and pre-configures your first user with sudo access during setup – one of a handful of small differences covered in our post on what is Debian, and how does it differ from Ubuntu. Neither approach is wrong, but it’s worth knowing about before you’re staring at a “command not found” error on a server you can only reach as root.
Once you’ve got a working sudo user, it’s worth locking down SSH and doing the rest of the initial hardening – see our initial server setup checklist for Debian for the full sequence.