The Linux operating system is known for its security and flexibility, allowing users to configure the system to their needs. One of the useful features of Linux, as well as other Unix-like systems, is the support for multiple users.
This feature dates back to the times when Unix-based computers (including Linux) were massive machines occupying entire rooms. A multi-user architecture was essential to allow multiple people to efficiently use such computing machines simultaneously while maintaining data and settings isolation for each user.
Today, this functionality remains relevant, as modern servers, cloud platforms, and even home computers are often used by multiple users. This ensures that each person can work independently without interfering with others and while keeping their data secure.
In this guide, we will explain in detail how to create a new user through the Linux terminal. Even if you're a beginner, don't worry — everything will be simple and clear.
1. Administrator privileges. To add new users, you need access to an account with superuser rights (sudo).
2. Basic commands. We will use the useradd and passwd commands to create a user and set a password.
Before proceeding, it’s useful to check the default parameters. Run the following command:
useradd -D
This command will display default settings, such as the user’s home directory or assigned shell. You can modify these settings if necessary.
To create a new user, execute the following command in the terminal:
sudo useradd -m username
The -m flag automatically creates a home directory at /home/username.
Replace username with the desired username.
Next, generate a password for the newly created user:
sudo passwd username
The system will ask you to enter the password twice to prevent errors.
Now your user is created and ready to use!
Example 1: User with a Custom Home Directory
If you want the user’s home directory to be located somewhere other than the default /home, specify the path using the -d flag:
sudo useradd -m -d /custom/path username
Set the password as usual:
sudo passwd username
Example 2: Temporary User with an Expiration Date
Sometimes, you may need to create a user with a limited lifespan. For example, to expire on October 1, 2025:
sudo useradd -m -e 2025-10-01 username
sudo passwd username
The -e flag sets the expiration date for the account.
Example 3: System User Without a Home Directory
If you need a system user without unnecessary settings, use the following command:
sudo useradd -r -M -s /bin/false -c "System User" username
→ -r creates a system user.
→ -M ensures that no home directory is created.
→ -s /bin/false prevents login access.
→ -c "System User" adds a description (visible in the /etc/passwd file).
System users (created with the -r flag) are not meant for logging in. They are used for background processes, services, and daemons, such as:
→ mysql
→ nginx
→ www-data
→ sshd
→ backup
List of users:
cat /etc/passwd
Check password status:
sudo chage -l username
Now you know how to add a user in Linux. If you have any questions, don’t hesitate to check the command manuals using man useradd! Good luck! 🚀
Apply the discount by inserting the promo code in the special field at checkout:
Apply the discount by inserting the promo code in the special field at checkout: