Create User Linux: adduser vs useradd, sudo and SSH Keys
- November 11, 2026
- 9:00 am
- By Adrien Roche
- Tutorials

Create a user on Linux: adduser or useradd
Every Linux distribution ships useradd, the low-level tool from shadow-utils. Debian and Ubuntu add adduser, a friendlier front end that asks questions and applies defaults from /etc/adduser.conf. Both need root.
1. Debian and Ubuntu: adduser
sudo adduser aliceOne command does everything: it picks the next free UID, creates a private group named alice, creates /home/alice from /etc/skel, sets /bin/bash as the shell, prompts for a password and then for optional details you can skip with Enter. For scripts, make it non-interactive:
sudo adduser --disabled-password --gecos "" alice--disabled-password leaves the account without a usable password until you set one, which is what you want for an SSH-key-only login. On adduser 3.130 and newer (Debian 12, Ubuntu 24.04) the option is named --comment; --gecos still works as an alias.
2. Any distribution: useradd -m
sudo useradd -m -s /bin/bash -c "Alice Example" alice
sudo passwd aliceuseradd does only what you tell it. -m creates the home directory (without it, Debian and Ubuntu create none; the RHEL family sets CREATE_HOME yes in /etc/login.defs, so they do). -s sets the login shell: the default from /etc/default/useradd is /bin/sh on Debian and Ubuntu, /bin/bash on RHEL; useradd -D shows it. -c fills the comment (GECOS) field. Because it never prompts, useradd is the right tool inside a provisioning shell script, with chpasswd reading the password from stdin:
sudo useradd -m -s /bin/bash alice
echo 'alice:CHANGE_ME' | sudo chpasswd
sudo passwd -e alice # new password required at first login3. Set, change or expire the password
sudo passwd alice sets or resets it; sudo passwd -S alice shows the status (P usable, L locked, NP none); sudo passwd -e alice forces a change at the next login. Later, sudo usermod -s /bin/bash alice changes the shell, sudo usermod -d /srv/alice -m alice moves the home with its contents, and sudo mkhomedir_helper alice builds a missing home from /etc/skel.
adduser vs useradd: Debian/Ubuntu versus the RHEL family
The differences that bite people moving between distributions:
| Task | Debian / Ubuntu | RHEL / Rocky / AlmaLinux / Fedora |
|---|---|---|
| Interactive creation | adduser alice (prompts, creates home and password) | adduser is a symlink to useradd: no prompts, run passwd after |
Plain useradd alice creates a home? | No, add -m | Yes (CREATE_HOME yes in login.defs) |
Default shell from useradd | /bin/sh | /bin/bash |
| Admin group | sudo (%sudo ALL=(ALL:ALL) ALL) | wheel (%wheel ALL=(ALL) ALL) |
sudo package present | Ubuntu: yes. Debian: not always | Yes |
| Delete user and home | deluser --remove-home alice | userdel -r alice |
| Remove from a group | deluser alice sudo or gpasswd -d alice sudo | gpasswd -d alice wheel |
Ubuntu's installer and cloud-init both put the first user in the sudo group. On Debian, if you typed a root password during installation, it is not, and the package itself may be missing: apt install sudo from a root shell, then continue below.
Give the new user sudo: usermod -aG sudo or wheel
Administrative rights on Linux come from group membership. The sudoers file on Debian and Ubuntu grants everything to the sudo group; the RHEL family uses wheel.
sudo usermod -aG sudo alice # Debian, Ubuntu
sudo usermod -aG wheel alice # RHEL, Rocky, AlmaLinux, Fedora
id aliceThe -a matters: usermod -G sudo alice without it replaces the whole list of supplementary groups, silently dropping docker or anything else the user had. sudo gpasswd -a alice sudo is an equivalent that cannot make that mistake. id alice should now end with 27(sudo) on Debian and Ubuntu or 10(wheel) on RHEL.
Membership is read when a session starts, so a user who is already logged in has to log out and back in (or run newgrp sudo) before sudo works. Test it without leaving your root session:
su - alice
sudo -v # asks alice's password; silent success means sudo works
sudo whoami # root
exitsu - starts a full login shell, which is why the new group shows up immediately; su, sudo -i and sudo -s are compared here. Removing the right is the reverse: sudo gpasswd -d alice sudo.
Edit sudoers with visudo, and think twice about NOPASSWD
When one account needs a different rule, such as a deploy user that may only restart a service, write it in a drop-in file, never by opening /etc/sudoers in a plain editor:
sudo visudo -f /etc/sudoers.d/alicevisudo locks the file and runs a syntax check before saving; a typo in sudoers otherwise locks every admin out of sudo at once. Drop-in files must be owned by root and not world-writable (0440 is the convention), and their name must not contain a dot or end in ~, or sudo skips them silently. Two example lines:
alice ALL=(ALL:ALL) ALL
deploy ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx, /usr/bin/systemctl reload nginxThe first is the standard full-admin rule for a user outside the sudo group; the second grants exactly two commands, with absolute paths. Because sudo applies the last matching rule, a drop-in can relax or tighten what the group rule already allows.
alice ALL=(ALL) NOPASSWD: ALL is the line most tutorials hand out for convenience, and it deserves a warning. The password prompt is the only thing between "some code runs as alice" and "some code is root": a stolen SSH key, a script piped into bash or a compromised process under that account becomes full root with no further check. A command list is also only as tight as its commands: anything that spawns a shell or opens arbitrary files (vim, less, find -exec) is equivalent to ALL. sudo already caches the password for 15 minutes by default; Defaults timestamp_timeout=30 extends that. Validate every file with sudo visudo -c.
Add an SSH key for the new user and stop logging in as root
On a fresh VPS you arrive as root with a password. The point of creating a user is to stop doing that: every bot already knows the username, and one mistyped rm has no safety net. Do the steps in this order.
1. Copy or upload the public key
From your own machine, while password authentication is still enabled, ssh-copy-id alice@SERVER_IP does everything. From a root session that already holds your key, copy it across and fix the ownership:
sudo mkdir -p /home/alice/.ssh
sudo cp /root/.ssh/authorized_keys /home/alice/.ssh/authorized_keys
sudo chown -R alice:alice /home/alice/.ssh
sudo chmod 700 /home/alice/.ssh
sudo chmod 600 /home/alice/.ssh/authorized_keysPermissions matter: with the default StrictModes yes, sshd ignores a group- or world-writable authorized_keys or a .ssh directory not owned by the user, and the only symptom is "Permission denied (publickey)".
2. Test from a second terminal
ssh alice@SERVER_IP
sudo -vKeep the root session open until both succeed. If the key is rejected, sudo journalctl -u ssh -n 30 (sshd on RHEL) names the reason.
3. Close the root door
Only now set PermitRootLogin no, PasswordAuthentication no and optionally AllowUsers alice in a drop-in under /etc/ssh/sshd_config.d/, then reload sshd. The full procedure, including fail2ban and UFW, is in enabling and hardening SSH on Ubuntu. Root remains reachable through sudo -i.
Lock, expire or delete a user
Lock: keep the account, block logins
sudo passwd -l alice # password only
sudo usermod -L --expiredate 1 alice # password AND accountpasswd -l (the same as usermod -L) prepends ! to the hash in /etc/shadow, which blocks password logins and nothing else: an SSH key keeps working, as the passwd man page itself warns. Setting the expiry date to day 1 (2 January 1970) disables the account for every authentication method. Undo both with sudo usermod -U --expiredate "" alice. Existing sessions survive a lock; end them with sudo loginctl terminate-user alice. A service account that should own files but never log in gets sudo usermod -s /usr/sbin/nologin alice instead.
Delete
sudo deluser --remove-home alice # Debian, Ubuntu
sudo userdel -r alice # any distributionBoth refuse while the user still has running processes ("currently used by process"); terminate the session first. -r and --remove-home delete the home directory and mail spool, not files elsewhere. Before deleting, list what the user owns outside the home and remove the crontab so nothing keeps running under an orphaned UID, which the next account created may inherit:
sudo find / -path /proc -prune -o -user alice -print
sudo crontab -r -u aliceAfterwards, sudo find / -nouser shows anything you missed. Debian's deluser --remove-all-files goes further and deletes every file the user owns; use it deliberately.
Audit users and sudo rights: /etc/passwd, id, getent
Each line of /etc/passwd holds seven colon-separated fields: login, an x meaning the hash lives in /etc/shadow, UID, primary GID, comment, home and shell. Prefer getent over reading the file: it also sees accounts from LDAP or SSSD.
getent passwd alice
getent passwd | awk -F: '$3 >= 1000 && $3 < 65534 {print $1, $3, $7}'
getent group sudo wheel
sudo -l -U aliceThe second line lists human accounts (UID 1000 and above on Debian, Ubuntu and RHEL alike; 65534 is nobody) with their shells. getent group sudo wheel answers "who can become root" in one line, and sudo -l -U alice prints every sudoers rule that applies to a user, drop-ins included. Then check each account's state and recent sudo use:
sudo passwd -S alice # L = locked, P = password set, NP = none
sudo chage -l alice # expiry and password ageing
sudo journalctl _COMM=sudo -n 50With rsyslog installed, sudo invocations also land in /var/log/auth.log (Debian, Ubuntu) or /var/log/secure (RHEL).
All of this assumes a server where you hold root from the first minute and can rebuild it if an experiment goes wrong. A Linux VPS from rdp.monster is exactly that: full root access, dedicated CPU and RAM, unlimited (fair-use) bandwidth, no KYC, crypto payments accepted, from $8.99 per month, online about 10 seconds after payment confirms. The first command you run on it can be the one that creates the user you will actually work from.
Frequently Asked Questions
Why does sudo say the user is not in the sudoers file?
id alice: on Debian and Ubuntu the list must include sudo, on RHEL, Rocky, AlmaLinux and Fedora wheel. If you just ran usermod -aG, the user has to log out and back in for the group to apply. On Debian, also confirm that the sudo package is installed and that /etc/sudoers still contains the %sudo ALL=(ALL:ALL) ALL line; sudo visudo -c reports syntax problems.How do I create a user without a password in Linux?
sudo adduser --disabled-password --gecos "" alice creates the account with the password field locked. On any distribution, sudo useradd -m -s /bin/bash alice without a following passwd does the same. The user cannot authenticate with a password, but an SSH key placed in ~/.ssh/authorized_keys works, which is the usual setup for automation and deploy accounts. Note that sudo will still ask for a password, so pair it with a scoped NOPASSWD rule or set one later.How do I create a system user for a service?
sudo useradd -r -s /usr/sbin/nologin -d /var/lib/myapp myapp; -r picks a system UID, skips password ageing and never creates the home, so add -m if the service needs one. On Debian and Ubuntu, sudo adduser --system --group --home /var/lib/myapp myapp is the equivalent and also creates a matching group. Then run the daemon with User=myapp in its systemd unit.How do I create a user with a specific UID or home directory?
sudo useradd -m -u 1500 -d /srv/alice -s /bin/bash alice creates the account with UID 1500 and its home at /srv/alice; the UID must be free, so getent passwd 1500 should return nothing first. Debian's front end does the same with sudo adduser --uid 1500 --home /srv/alice alice. Matching UIDs across machines matters for NFS mounts, container volumes and rsync --numeric-ids, which is the usual reason to pin one. For an existing account, usermod -u changes the UID and usermod -d /new/path -m moves the home.Adrien Roche, Infrastructure & Hosting Editor
Systems engineer with 10+ years operating Windows Server and Linux fleets. Adrien runs the rdp.monster infrastructure documentation and writes our guides on RDP, VPS hosting, server administration, networking and privacy tooling.
Related Posts




