Every person and every app that logs in to your server should have its own account. Working as root all day makes mistakes costly and hides who did what. This guide shows how to add a user on Ubuntu, Debian, AlmaLinux and Rocky Linux, and explains the difference between the two commands you will meet: adduser and useradd.
Before you start
- A Linux VPS running Ubuntu 22.04 or 24.04, Debian 12, or AlmaLinux or Rocky Linux 8 or 9.
- An SSH session as root or a user with sudo. Your root login details are in your VPS provider's control panel.
- A name for the new account. Use lowercase letters, digits, hyphens or underscores, starting with a letter, for example
deploy.
adduser vs useradd
Both commands create users, but they behave differently:
useraddis the low-level tool and exists on every distribution. It does only what you tell it with options. On Debian and Ubuntu it does not create a home folder unless you pass-m, and it may set the shell to/bin/sh.adduseron Debian and Ubuntu is a friendly wrapper. It creates the home folder, copies the default files from/etc/skel, sets the shell to Bash and asks for a password.- On AlmaLinux and Rocky Linux,
adduseris just a link touseradd. It does not ask questions, but the defaults there already create a home folder and use Bash.
In short: use adduser on Debian and Ubuntu, and useradd on AlmaLinux and Rocky.
Add a user on Ubuntu and Debian
Run:
sudo adduser deployThe command creates the group and home folder, then asks for a password twice and for optional details such as full name. Press Enter to skip the details. The output starts like this:
info: Adding user `deploy' ...
info: Adding new group `deploy' (1001) ...
info: Adding new user `deploy' (1001) with group `deploy (1001)' ...
info: Creating home directory `/home/deploy' ...
info: Copying files from `/etc/skel' ...
New password:Older releases print the same lines without the info: prefix.
To create the user without the questions, for example in a script, set the details on the command line and the password separately:
sudo adduser --disabled-password --gecos "" deploy
sudo passwd deployAdd a user on AlmaLinux and Rocky Linux
Use useradd with explicit options so the result is clear:
sudo useradd -m -s /bin/bash deploy
sudo passwd deploy-mcreates/home/deployand copies files from/etc/skel.-s /bin/bashsets the login shell.passwdsets the password. Until you do, the account cannot log in with a password.
The same two commands also work on Debian and Ubuntu if you prefer one method everywhere.
Useful extra options
-c "Deploy user"adds a comment, usually the full name.-G wheel(AlmaLinux, Rocky) or-G sudo(Ubuntu, Debian) adds the user to that group at creation, which grants sudo rights.-u 1050picks a specific user ID, handy when IDs must match across servers.-e 2026-12-31sets an expiry date for a temporary account.
Give the user sudo rights (optional)
Only add sudo if the person really needs to administer the server.
Ubuntu and Debian:
sudo usermod -aG sudo deployAlmaLinux and Rocky Linux:
sudo usermod -aG wheel deployThe full walkthrough, including testing, is in Create a sudo user on Linux.
Set up SSH key login for the user
A password works, but SSH keys are safer. Copy your public key into the new account from your own computer:
ssh-copy-id deploy@203.0.113.10If you work from Windows without ssh-copy-id, follow Set up SSH keys to add the key by hand to /home/deploy/.ssh/authorized_keys.
Check it works
Confirm the account exists and has the right shell and home:
getent passwd deploydeploy:x:1001:1001::/home/deploy:/bin/bashThe last two fields are the home folder and shell. Then check the groups and test a login from a new terminal:
id deploy
ssh deploy@203.0.113.10Once logged in, pwd should print /home/deploy.
Troubleshooting
- "useradd: user 'deploy' already exists": the name is taken. Check with
getent passwd deployand pick another name or work with the existing account. - Login drops you into
$with no colours or tab completion: the shell is/bin/sh. Fix it withsudo usermod -s /bin/bash deploy. - "Could not chdir to home directory": the account was made without
-m. Create the folder withsudo mkhomedir_helper deploy, or by hand withsudo mkdir /home/deployandsudo chown deploy:deploy /home/deploy. - "Permission denied" at SSH login with the right password: password login may be disabled in
sshd_config. Use SSH keys for the new user instead. - "adduser: Please enter a username matching the regular expression": the name has capitals or unusual characters. Use lowercase letters and digits.
Next steps
- Put the user in the right groups: Add a user to a group in Linux.
- See every account on the server: List users and groups on Linux.
- Remove an account you no longer need: Delete a user and their files.
