Linux Operating System and User Management
Linux is well known for its reliability, security, and flexibility in customization. One of its key features, like other Unix-based systems, is multi-user support.
This feature originated in the early days when Unix-based computers occupied entire rooms. A multi-user architecture was essential for allowing multiple individuals to use a single machine simultaneously while maintaining data and configuration isolation.
Today, this capability remains relevant, as servers, cloud services, and even personal computers are often used by multiple users. It ensures that each user can work independently without interfering with others while keeping their data secure.
In this guide, we will explain how to create a new user via the Linux terminal. Even if you’re a beginner, don’t worry—everything will be simple and clear.
What You Need to Know Before Starting
- Administrator Privileges – To add new users, you need access to an account with superuser (sudo) rights.
- Basic Commands – We will use
useradd
andpasswd
to create a user and set a password.
Step 1: Checking Default Settings
Before creating a new user, it’s useful to check the current default settings. Run the following command:
useradd -D
This will display parameters such as the default shell and home directory. You can modify these settings if needed.
Step 2: Creating a User
To add a new user, execute the following command:
sudo useradd -m username
- The
-m
flag automatically creates the/home/username
directory. - Replace
username
with your desired username.
Next, set a password:
sudo passwd username
The system will ask you to enter the password twice for verification.
Your new user is now ready to use!
Usage Examples
1. User with a Custom Home Directory
If you need to specify a non-standard home directory, use the -d
flag:
sudo useradd -m -d /custom/path username
Then, set the password:
sudo passwd username
2. Temporary User with an Expiration Date
To create a user with an account that expires 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.
3. System User Without a Home Directory
To create a system user without a personal home directory, use:
sudo useradd -r -M -s /bin/false -c "System User" username
-r
creates a system user.-M
prevents the creation of a home directory.-s /bin/false
disables login access.-c "System User"
adds a description (visible in/etc/passwd
).
System users are designed for background services and processes, such as:
mysql
nginx
www-data
sshd
backup
Useful Commands and Files
List all users:
cat /etc/passwd
Check password expiration:
sudo chage -l username
Now you know how to add users in Linux. If you have questions, consult the command manual using man useradd
. Good luck!