Last Updated : 11 Jul, 2025
User management is one of the fundamental tasks in Linux systems administration because a user has to go through a series of access controls to keep an environment secure and organized. It provides functionalities that include adding, modifying, and deleting user accounts, assigning privileges, and setting password policies. One must know how to manage users to keep the system secure and efficient.
What is Users in Linux System Administration?In Linux system administration, a user is an individual or system entity that can log in and access the system. Users in Linux are managed through unique accounts with assigned User IDs (UIDs), permissions, and roles.
Types of Users in Linux:0
.www-data
, mysql
).The useradd command is used to create a new user in Linux. Its basic syntax is:
Syntax:
useradd [options] USERNAME
In Linux, user management is crucial for system security, access control, and permissions.
Command Description Syntax & Exampleadduser
Create a new user in Linux. sudo adduser username
sudo adduser john
useradd
Another command to add a new user (without creating a home directory). sudo useradd username
sudo useradd mike
passwd
Set or change a user’s password. sudo passwd username
sudo passwd john
deluser
Remove a user from the system. sudo deluser username
sudo deluser mike
userdel
Another command to delete a user but doesn’t remove the home directory by default. sudo userdel username
sudo userdel mike
usermod
Modify user account properties, such as username, home directory, or groups. sudo usermod -l newname oldname
sudo usermod -l david john
id
Display user ID (UID) and group ID (GID) information. id username
id john
whoami
Show the currently logged-in user. whoami
who
List all users currently logged into the system. who
w
Show logged-in users and their activity. w
last
Display login history of users. last
groups
Show groups a user belongs to. groups username
groups john
groupadd
Create a new user group. sudo groupadd groupname
sudo groupadd developers
groupdel
Delete a group. sudo groupdel groupname
sudo groupdel developers
usermod -aG
Add a user to a group. sudo usermod -aG groupname username
sudo usermod -aG sudo john
chage
Set or check password expiry details for a user. sudo chage -l username
sudo chage -l john
getent passwd
List all users on the system. getent passwd
awk -F:
Display only the usernames of all users. awk -F: '{print $1}' /etc/passwd
compgen -u
Show all system users. compgen -u
sudo visudo
Edit sudo privileges for users. sudo visudo
`who wc -l` Count the number of currently logged-in users. Basic useradd Command Example in Linux System Administration
Without any options, the simplest use of the useradd command looks like this:
sudo useradd <username>
This creates a user with the default settings.
Users are accounts that can be used to login into a system. Each user is identified by a unique identification number or UID by the system. All the information of users in a system are stored in /etc/passwd
file. The hashed passwords for users are stored in /etc/shadow
file. Users can be divided into two categories on the basis of the level of access:
When a new user is created, by default system takes following actions:
/home/
./bin/sh
./etc/skel
are copied to the home directory of the new user.This file is readable by any user but only root as read and write permissions for it. This file consists of the following colon separated information about users in a system:
Syntax:
[username]:[password]:[UID]:[GID]:[GECOS]:[home_dir]:[shell_path]
Example:
2. Description of contents of the /etc/shadow FileThis file is readable and writable by only by root user. This file consists of the following colon separated information about password of users in a system:
Syntax:
[username]:[enc_pwd]:[last_pwd_change]:[pwd_validity]:[warn_date]:[acc_validity]:[acc_disablity]
Example:
Common Options Used with the useradd Command in Linux System AdministrationOption
Description
-m
Create the user’s home directory.
-d
Specify a custom home directory.
-s
Define the user’s default shell.
-G
Add the user to additional groups.
-e
Set an expiration date for the user account.
-c
Add a comment (typically the full name of the user).
Detailed Explanation of useradd Options 1. -m Option (Create Home Directory)By default, useradd does not create a home directory. Use the -m option to ensure the user gets a home directory:
sudo useradd -m kavya2. -d Option (Custom Home Directory)
To assign a non-default home directory, use the -d option:
sudo useradd -d /custom/home kavya3. -s Option (Specify Default Shell)
Set a specific shell for the user with the -s option:
sudo useradd -s /bin/bash kavya
This sets Bash as the user's default shell.
4. -G Option (Add User to Groups)To add a user to additional groups, use the -G option:
sudo useradd -G sudo,developers kavya5. -e Option (Set Expiration Date)
To set an expiration date for a user account:
sudo useradd -e 2024-12-31 kavya
This sets the account to expire at the end of 2024.
ConclusionUser management is one of the cardinal aspects in Linux system administration. It ensures proper resource allocation and keeps your system secure. The useradd command and all of its options give the administrator an in-depth way to create and edit user accounts according to their needs. Knowing how to use them would vastly simplify user administration for accommodating user environments, access levels, and even policy enforcements. The system administrator will be able to maintain the Linux environment secure, productive, and organized with the usage of universal commands such as useradd.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4