How to Create a User in Linux [With Examples]
User management is one of the first tasks on any new Linux server. Every person or service that interacts with the system needs its own account, with the right permissions and group memberships. Getting this wrong leads to security gaps, broken services, or locked-out administrators.
In this tutorial, you will create users using both adduser and useradd, modify existing accounts, create system users for services, and delete users when no longer needed.
#Prerequisites
To follow along, ensure you have the following in place:
-
A Linux system. This guide uses Ubuntu 24.04 LTS, but the
useraddexamples work on any Linux distribution. -
Root access or a user with sudo privileges.
#Linux user groups
There are two broad categories of users in Linux: regular and system users. Regular users are created by the root or administrative user (sudo user). These users have login capabilities and home directories that contain personal files and folders.
On the other hand, Linux system users are created by the system during the installation of the operating system or software applications. They are used by the system to run services.
Note: For further guidance on managing Linux users, check our guide on how to list users in Linux.
#How to create a user in Linux?
The adduser and useradd are command-line tools used to create new users in Linux/UNIX systems. The two perform the same task but use different execution methods. So, let's dive right in; below, I'll explain each method with a specific example of how to create a user in Linux.
#Option 1: The adduser command
The adduser command-line tool is a utility native to Debian-based distributions such as Ubuntu, Debian, and Mint for creating users in Linux. It's a more powerful, user-friendly command-line utility for adding users than useradd. It provides an interactive approach for adding users, where user creation is displayed step-by-step on the screen. The adduser command syntax is pretty straightforward. You simply type adduser followed by the name of the user that you want to create.
sudo adduser username
For example, to create a new user called alex, run the command:
sudo adduser alex
Once invoked, the command creates a new user and group with the same name as the user being created. It then adds the user to the group and creates a home directory for the user. In addition, it copies files from the /etc/skel directory to the new user's home directory.
The /etc/skel directory contains files and directories required in the new user's directory. These include the .bashrc, .bash_logout, and .profile configuration files.
Next, you will be prompted to provide the user's password. Once you have provided and confirmed the password, you will be required to provide additional information about the user, such as full name, room number, work phone, and home phone. Fill in the information where applicable, or hit ENTER to skip.
To save the information provided, type 'Y' and hit ENTER.
Outputinfo: Adding user `alex' ...
info: Selecting UID/GID from range 1000 to 59999 ...
info: Adding new group `alex' (1001) ...
info: Adding new user `alex' (1001) with group `alex (1001)' ...
info: Creating home directory `/home/alex' ...
info: Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for alex
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
info: Adding new user `alex' to supplemental / extra groups `users' ...
info: Adding user `alex' to group `users' ...
To confirm the creation of the user, run the id command followed by the username of the user.
id alex
Outputuid=1001(alex) gid=1001(alex) groups=1001(alex),100(users)
This prints out the UID (User ID), GID (Group ID), and the groups the user belongs to.
Alternatively, you can view the /etc/passwd file, which is a colon-separated file that stores user information.
cat /etc/passwd | grep -i alex
Outputalex:x:1001:1001:,,,:/home/alex:/bin/bash
As you can see, the adduser command is straightforward and easy to use, especially for beginners. Also, note that the command requires root or superuser privileges. That implies you will always have to run it as root or invoke sudo before the command if you are running it as a sudo user.
#Option 2: The useradd command
The useradd is another command-line utility for creating users in a Linux system. It comes included in all Linux distributions by default. Like its counterpart adduser command, only root or sudo users can create new accounts with useradd.
The useradd utility refers to the /etc/login.defs file, from where it applies default user parameters such as the range of User IDs and Group IDs, password aging controls, login timeout, etc.
The syntax for the useradd command is as follows.
useradd [OPTIONS] username
Various options can be used alongside the useradd command to specify user attributes. Let's look at some of the commonly used useradd command-line options.
#1. Create a new user without any options
The useradd command can be used to create a user without invoking any command-line options. For example, to create a user called alice, run the command:
sudo useradd alice
The command appends an entry to the /etc/passwd, /etc/shadow, /etc/gshadow, and /etc/group files.
Next, set the password using the passwd command to enable the user to login to the system. So, invoke the passwd command followed by the username.
passwd alice
Be sure to provide a strong password and confirm it.
New password:
Retype new password:
passwd: password updated successfully
Once done, confirm that the user has been created by running the id command.
id alice
Outputuid=1002(alice) gid=1002(alice) groups=1002(alice)
Additionally, you can search for the user's entry in the /etc/passwd file as shown.
cat /etc/passwd | grep -i alice
Outputalice:x:1002:1002::/home/alice:/bin/sh
#2. Create a User with a Specific User ID
By default, the system automatically assigns the next available UID from the range of user IDs contained in the /etc/login.defs file.
The -u (--uid) option allows you to define a specific User ID for the user.
For example, to create a user called bob with a UID of 1005, run the command:
sudo useradd -u 1005 bob
Once again, you can verify the UID using the id command:
id bob
From the output below, you can see that the user bob has acquired a UID of 1005, which also happens to be its GID.
Outputuid=1005(bob) gid=1005(bob) groups=1005(bob)
Also read: Linux shutdown command guide
#3. Create a User with a Specific Group ID
When a new user is created, it belongs to a primary group whose Group ID ( GID ) is the same as the User ID ( UID ). Suppose you want to assign a different GID other than the default. You can achieve this by passing the -g (--gid) option and specifying the group name or GID number.
For example, to create a user called john with a GID of 100, run the command:
sudo useradd -g 100 john
Alternatively, you can specify the group name corresponding to the GID number. In this case, the users group corresponds to GID 100.
sudo useradd -g users john
You can verify the group the user belongs to using the id command:
id -gn john
OR
id john
Outputuid=1006(john) gid=100(users) groups=100(users)
NOTE: The group the user is being added to must already exist for this operation to succeed.
#4. Create a Linux user and assign multiple groups
A Linux user can belong to two broad categories of groups: exactly one primary group, which is the default group, and one or multiple secondary groups.
You can pass the -G (--groups) option to specify one or more secondary groups that the user belongs to. For instance, in the command below, we are creating a user called mark with a primary group called users and belonging to secondary groups called wheel, kvm, and ftp.
sudo useradd -g users -G wheel,kvm,ftp mark
To verify this, once again, run the id command.
id mark
Outputuid=1007(mark) gid=100(users) groups=100(users),993(kvm),1006(wheel),1007(ftp)
#5. Create a new user with a home directory
A home directory is a login directory that contains the user's files and folders as well as environment setting files. This is the directory a user lands into upon login.
In older Linux distributions, the home directory is not created by default using the useradd command.
Pass the -m (--create-home) option to create a user home directory in the /home/<username> path.
For instance, to create a user called patrick with a home directory in the /home/patrick path, run the command:
sudo useradd -m patrick
You can confirm the creation of the user's home directory using the ls -la command as shown.
ls -la /home/patrick
The output lists the user's initialization files which are typically present in any user's home directory.
Outputtotal 20
drwxr-x--- 2 patrick patrick 4096 Mar 16 09:36 .
drwxr-xr-x 5 root root 4096 Mar 16 09:36 ..
-rw-r--r-- 1 patrick patrick 220 Mar 31 2024 .bash_logout
-rw-r--r-- 1 patrick patrick 3771 Mar 31 2024 .bashrc
-rw-r--r-- 1 patrick patrick 807 Mar 31 2024 .profile
#6. Create a user with a unique home directory
As you can see, the default user's home directory is in the /home directory. To specify a different location, pass the `-d' option.
In the following example, we create a new user called bill with the home directory specified as opt/bill.
sudo useradd -m -d /opt/bill bill
cat /etc/passwd | grep -i bill
Outputbill:x:1009:1009::/opt/bill:/bin/sh
#7. Create a user without a home directory
If you wish to exclude the creation of the user's home directory, pass the -M option followed by the username. In the following example, we create a new user called sandra without the home directory.
sudo useradd -M sandra
To verify that the system skipped creating the home directory, run the command:
sudo ls -la /home/sandra
Outputls: cannot access '/home/sandra': No such file or directory
From the output, the contents of the home directory were not listed for the simple reason that the directory was not created.
#8. Create a user with a specific comment
A comment is simply a short description of the user. I can include anything from a phone number to a job title to a residence. To add a description, use the -c option.
In this example, we are creating a new user called george with the job title "Human Resource Manager" as the comment.
sudo useradd -c "Human Resource Manager" george
cat /etc/passwd | grep -i george
Outputgeorge:x:1011:1011:Human Resource Manager:/home/george:/bin/sh
#9. Create a user with an account expiry date
Lastly, you can create a new user and enforce an account expiry date. Once the account expires, the user will no longer be able to log in. This is mostly used when creating temporary users.
The expiry date is expressed in YYYY-MM-DD format.
For example, to create a new user called kristin whose account expires on 2027-06-10, run the command:
sudo useradd -e 2027-06-10 kristin
Invoke the chage command to confirm the user account expiry date.
sudo chage -l kristin
OutputLast password change : Mar 16, 2026
Password expires : never
Password inactive : never
Account expires : Jun 10, 2027
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7
#How to delete a user in Linux
When someone leaves your team or an account is no longer needed, remove it from the system. Two commands handle user deletion: userdel (works on all Linux distributions) and deluser (Debian/Ubuntu-specific).
#Delete a user with userdel
Remove a user account but keep the home directory:
sudo userdel kristin
Remove a user and delete the home directory and mail spool:
sudo userdel -r kristin
The -r flag removes the user's home directory (/home/kristin) and any files inside it. Always verify you have backed up the needed files before using this flag.
#Delete a user with deluser
On Debian and Ubuntu systems, deluser provides a friendlier interface:
sudo deluser kristin
Remove the user along with the home directory:
sudo deluser --remove-home kristin
After deletion, confirm the user no longer exists:
id kristin
The output should return "no such user." Also, check that the home directory has been removed with ls /home/.
#How to modify an existing user
The usermod command changes attributes of an existing user account. Here are the most common modifications.
#Change a username
Rename user alice to alicia:
sudo usermod -l alicia alice
The -l flag changes the login name. The home directory and UID remain the same. To also rename the home directory, add the -d and -m flags:
sudo usermod -l alicia -d /home/alicia -m alice
#Change the default shell
Set the user's login shell to /bin/zsh:
sudo usermod -s /bin/zsh alicia
Verify the change:
grep alicia /etc/passwd
The last field in the output shows the new shell.
#Lock and unlock a user account
Lock an account to prevent login without deleting it:
sudo usermod -L alicia
Unlock the account later:
sudo usermod -U alicia
Locking is useful when you need to temporarily disable access during an investigation or leave period. The user's files, home directory, and group memberships remain intact.
#Add a user to additional groups
Add user alicia to the docker and www-data groups without removing existing group memberships:
sudo usermod -aG docker,www-data alicia
Always use the -a (append) flag with -G. Without -a, the command replaces all secondary groups instead of adding to them.
#How to create a system user
System users run background services like Nginx, MySQL, and Prometheus. They have no login shell and no home directory by default.
Create a system user:
sudo useradd --system --no-create-home --shell /usr/sbin/nologin prometheus
The --system flag assigns a UID from the system range (below 1000). The --no-create-home flag skips home directory creation. The --shell /usr/sbin/nologin flag prevents interactive login.
Verify the system user:
id prometheus
System users appear in /etc/passwd with /usr/sbin/nologin or /bin/false as their shell. They cannot log in via SSH or a local terminal.
#adduser vs. useradd: key differences
Both commands create users, but they work differently. Here is a side-by-side comparison:
| Feature | adduser | useradd |
|---|---|---|
| Availability | Debian/Ubuntu only | All Linux distributions |
| Interface | Interactive (prompts for details) | Non-interactive (flags only) |
| Home directory | Created automatically | Requires -m flag |
| Password | Prompted during creation | Must run passwd separately |
| Default shell | Set to /bin/bash |
May default to /bin/sh (depends on distro) |
| User info (GECOS) | Prompted during creation | Requires -c flag |
| Best for | Quick manual user creation | Scripting and automation |
Use adduser when creating users manually on Debian or Ubuntu systems. Use useradd when writing scripts that need to work across different Linux distributions, or when you need precise control over every account attribute.
#Troubleshooting common user creation issues
#"useradd: user already exists"
The username is already taken. Check with id <username> or grep <username> /etc/passwd. Choose a different name or delete the old account first if it is no longer needed.
#Home directory not created
With useradd, the home directory is not created unless you pass the -m flag. If you forgot, create it manually:
sudo mkdir /home/username
sudo cp -r /etc/skel/. /home/username/
sudo chown -R username:username /home/username
#User cannot log in after useradd
The useradd command does not set a password by default. The account is locked until you run sudo passwd username. Without a password, SSH and local login will both fail.
#"Permission denied" when creating users
Only root or sudo users can create new accounts. Prefix the command with sudo, or switch to root with su -.
#Shell not set correctly
On some distributions, useradd defaults to /bin/sh instead of /bin/bash. Override this with the -s flag:
sudo useradd -m -s /bin/bash username
Or change it after creation:
sudo usermod -s /bin/bash username
#Conclusion
Proper user management is the foundation of Linux server security and access control. Separating accounts by person and service ensures accountability, limits damage from mistakes, and simplifies auditing.
The adduser command handles quick manual creation on Debian and Ubuntu, while useradd gives you precise control for scripting across any distribution.
For the next step, learn how to grant sudo privileges to your newly created users, or check our guide on how to list users in Linux to audit accounts on your system.
FAQs
What is the difference between adduser and useradd?
`adduser` is a Debian/Ubuntu wrapper that interactively prompts for a password, home directory, and user details. `useradd` is a low-level command available on all Linux distributions that requires explicit flags for each setting. Use `adduser` for quick manual creation and `useradd` for scripting.
How do I create a user without a password in Linux?
Run `sudo useradd -m username` to create the account, then skip the `passwd` step. The account will exist but remain locked until a password is set. You can also disable the password with `sudo passwd -d username`, but this is not recommended for security reasons.
Can I create multiple users at once?
There is no built-in command for batch user creation. Write a short shell script that loops through a list of usernames and calls `useradd` for each one. For example: `for user in alice bob carol; do sudo useradd -m -s /bin/bash $user; done.`
How do I check if a user exists on the system?
Run `id username`. If the user exists, the command prints their UID, GID, and group memberships. If not, it returns "no such user." You can also search the passwd file with `grep username /etc/passwd`.
What is the /etc/skel directory?
The `/etc/skel` directory contains default configuration files (`.bashrc`, `.profile`, `.bash_logout`) that are copied into a new user's home directory during account creation. Administrators can add files to `/etc/skel` to provide custom defaults for all new users.
How do I change a user's password?
Run `sudo passwd username` and enter the new password twice. To force a user to change their password at next login, run `sudo passwd -e username`. The `-e` flag expires the current password immediately, prompting the user to set a new one at their next login.
Starting at just $3.51 / month, get virtual servers with top-tier performance.