Creating user accounts is a basic but essential Linux administration task. This guide walks you through adding new users from the command line, setting their passwords, and assigning them to groups. You’ll learn the exact commands to run and what each one does, so you can confidently manage accounts on any Linux system.
What You’ll Need
- A Linux system with a terminal (any distribution, e.g., Ubuntu, Debian, CentOS, Fedora).
- Access to an account with
sudoprivileges (or the root password). - Basic familiarity with the command line.
Step-by-Step
-
Open a terminal.
On most desktop systems, you can press
Ctrl+Alt+Tor find “Terminal” in your applications menu. On a server, log in via SSH. -
Run the
useraddcommand with sudo.The basic syntax is:
sudo useradd username. Replaceusernamewith the desired login name (e.g.,alice). This creates the user but does not set a password yet. -
Set a password for the new user.
Use the
passwdcommand:sudo passwd alice. You’ll be prompted to enter and confirm the password. Choose a strong one (at least 8 characters, mixing letters, numbers, and symbols). -
Verify the user was created.
Check the account details with:
id alice. This shows the user ID (UID), group ID (GID), and the groups the user belongs to. By default, a group with the same name as the user is created. -
Create a home directory (if not auto-created).
On many distributions,
useradddoes not create a home directory by default. To create one and populate it with default files, use:sudo useradd -m alice. The-mflag creates the home directory at/home/alice. -
Set the user’s shell (optional).
To specify a login shell (e.g., Bash), use:
sudo useradd -m -s /bin/bash alice. If you omit this, the system default shell (usually/bin/sh) is used. -
Add the user to additional groups.
If the user needs access to certain resources (like
sudofor admin rights, ordockerfor container management), add them with:sudo usermod -aG sudo alice. The-aGflags append to the group list without removing existing groups. -
Test the new account.
Log out of your current session and log in as the new user, or switch to them with:
su - alice. This ensures the account works and the home directory is accessible.
Common Mistakes
- Forgetting the
-mflag – Without it, the user has no home directory, which can cause issues with many applications. - Not setting a password – A user without a password cannot log in. Always run
passwdafter creating the account. - Using
usermodwithout-aG– If you omit-a, the user is removed from all groups not listed in the command, which can lock them out of essential permissions. - Creating duplicate usernames – Linux usernames must be unique. Check with
id usernamebefore adding.
Tips
- Use the
addusercommand on Debian/Ubuntu systems – it’s a friendlier wrapper that creates the home directory, sets the shell, and prompts for a password interactively. - Set an expiration date for temporary accounts with
sudo chage -E 2025-12-31 alice. - To see all users on the system, view the
/etc/passwdfile:cat /etc/passwd. - Always use
sudoinstead of logging in as root when possible – it leaves an audit trail and reduces risk.
Troubleshooting
- “useradd: command not found” – The command might not be in your PATH. Try the full path:
/usr/sbin/useradd, or install thepasswdpackage if on a minimal system. - “Permission denied” when running sudo – Your account may not have sudo rights. Log in as root (if you know the root password) or boot into recovery mode to fix sudoers.
- User cannot log in – Check that the password is set and the account is not locked. Run
sudo passwd -S aliceto see status. If locked, unlock withsudo passwd -u alice. - Home directory not created – If you already created the user without
-m, you can create the directory manually:sudo mkdir /home/aliceand set ownership:sudo chown alice:alice /home/alice.
Frequently Asked Questions
What is the difference between useradd and adduser?
useradd is the low-level utility, while adduser is a Perl script that uses useradd but provides a more interactive, user-friendly experience, automatically creating the home directory and prompting for a password.
How do I delete a user?
Use sudo userdel -r username. The -r flag removes the user’s home directory and mail spool. Without -r, the home directory remains.
Can I create a user without a home directory?
Yes, simply omit the -m flag. This is sometimes done for system accounts that don’t need a home directory, like service accounts.
How do I change a user’s password after creation?
Run sudo passwd username and follow the prompts. You can also force the user to change it at next login with sudo chage -d 0 username.
What is a UID and why does it matter?
UID (User ID) is a numeric identifier for the user. The system uses it internally for permissions. Regular users typically have UIDs starting at 1000 (or 500 on some systems). You can specify a UID with sudo useradd -u 1500 alice.
How do I add a user to the sudo group?
On Debian/Ubuntu, use sudo usermod -aG sudo alice. On RHEL/CentOS/Fedora, use sudo usermod -aG wheel alice. The user must log out and back in for the change to take effect.
Related
General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.
More in this bed
- Google Photos Backup Stuck? Fixes That Work
- Record Your Own Alarm Sound on Android
- Transfer Music from ZTE to iPhone: Full Guide
- Angel Investor vs Venture Capitalist: Key Differences
- Sync Apps Between Android Devices Using Google Play
- Find What Drains Your iPhone Battery Fast