How-to

Create a Sudo User on Debian

Debian machines arrive with root and a password from the panel. A named admin account with sudo is the first thing to set up after logging in.

Is sudo installed on Debian by default?

Not always. Debian's installer only adds sudo when you leave the root password empty during setup; with a root password set, which is how our machines are delivered, the package may be missing. Check and install it as root:

command -v sudo || apt install sudo

Debian 13 "trixie" and Debian 12 "bookworm" both ship sudo in the main repository. The steps below are identical on both releases.

Which command adds the account on Debian?

Use adduser, Debian's friendly wrapper, which creates the home folder, copies default files and asks for a password:

adduser nadia

Enter a long password when asked; it will be used for sudo prompts on the machine, not for SSH once keys are set up. The name, room and phone questions can be left blank. On Debian 13, adduser creates home directories with mode 700 by default, so other users cannot browse them. The difference between adduser and the lower-level useradd is covered in Create a Linux user.

How do I give the user sudo rights?

Add them to the sudo group. Debian's /etc/sudoers already contains a rule letting members of that group run any command after entering their own password:

usermod -aG sudo nadia
id nadia

The -a matters: without it, usermod -G replaces all of the user's extra groups instead of adding one. id should now list 27(sudo). Group changes apply at the next login, so an already open session of that user will not see them.

How do I give the user my SSH key?

If you saved your key in the panel, it was placed for root at install time. Copy it to the new account with correct ownership and modes:

install -d -m 0700 -o nadia -g nadia ~nadia/.ssh
cp /root/.ssh/authorized_keys ~nadia/.ssh/
chown nadia:nadia ~nadia/.ssh/authorized_keys && chmod 0600 ~nadia/.ssh/authorized_keys

If root has no key yet, run ssh-copy-id nadia@your-address from your computer instead; it logs in with the password once and installs the key. Creating a key is explained in Log in with an SSH key.

How do I test it?

Keep the root session open and, from a new terminal on your computer, log in as the new user and confirm sudo works:

ssh nadia@203.0.113.25
sudo -v && echo "nadia has sudo"
sudo apt update

sudo -v asks for nadia's password and refreshes the sudo timestamp without running anything. If it says the user is not in the sudoers file, log out and back in so the new group is picked up.

Should I let the user run sudo without a password?

For a human, usually not. The password prompt is the last check if someone steals a session or a key. For automation accounts that run fixed commands, a narrow rule is fine. Put it in its own file and validate it:

echo 'deploybot ALL=(root) NOPASSWD: /usr/bin/systemctl restart php8.4-fpm' > /etc/sudoers.d/deploybot
chmod 0440 /etc/sudoers.d/deploybot
visudo -cf /etc/sudoers.d/deploybot

A syntax error in a sudoers file can break sudo for everyone, so always check with visudo -c. On Debian 13 the PHP version in the service name is 8.4; on Debian 12 it is 8.2.

What should I do about root afterward?

Once the new account works with a key and sudo, limit root over SSH. Set PermitRootLogin no, or prohibit-password if you want to keep key-based root access, in a drop-in under /etc/ssh/sshd_config.d/, check with sshd -t and reload with systemctl reload ssh. The options are compared in SSH root login settings. You can also lock root's password with passwd -l root, which blocks password logins for root everywhere while sudo keeps working.

What is the summary in one block?

StepCommand
Install sudoapt install sudo
Create useradduser nadia
Grant sudousermod -aG sudo nadia
Add keyssh-copy-id nadia@host
Testsudo -v in a new session

Keep Reading

The sudo command

How sudo decides who may run what, the flags you use daily, safe sudoers rules, logging and the habits that keep root powers contained.

Open

SSH root login settings

What each PermitRootLogin value does, how to move daily work to a sudo user and when key-only root login is reasonable.

Open

Create a Linux user

Create human and service accounts with useradd: home folders, shells, UIDs, groups, expiry, skeleton files and system accounts.

Open

Debian

Debian 13 or 12 for servers that should change as little as possible between upgrades, on any machine we sell.

Open

FAQ

Quick Answers

The sudo group. Members can run any command after entering their own password.

The user is not in the sudo group yet, or has not logged in again since being added.

It may be missing when a root password is set. Install it with apt install sudo.

adduser is the friendlier wrapper that sets up the home folder and password interactively.

Run visudo -c, or visudo -cf with the file path for a single drop-in.