Open In App

Users in Linux System Administration

Last Updated : 05 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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:

  • Root User (Administrator) – The superuser with full control over the system, identified by UID 0.
  • Regular Users – Non-administrative users created for daily operations assigned unique UIDs.
  • System Users – Users created by the system for running services like databases and web servers (e.g., www-data, mysql).

The useradd command is used to create a new user in Linux. Its basic syntax is:

Syntax:

useradd [options] USERNAME
  • USERNAME: The name of the user to be created.
  • [options]: Additional parameters to customize the creation process.

Useful Linux Commands for User Management

In Linux, user management is crucial for system security, access control, and permissions.

CommandDescriptionSyntax & Example
adduserCreate a new user in Linux.sudo adduser username
Example: sudo adduser john
useraddAnother command to add a new user (without creating a home directory).sudo useradd username
Example: sudo useradd mike
passwdSet or change a user’s password.sudo passwd username
Example: sudo passwd john
deluserRemove a user from the system.sudo deluser username
Example: sudo deluser mike
userdelAnother command to delete a user but doesn’t remove the home directory by default.sudo userdel username
Example: sudo userdel mike
usermodModify user account properties, such as username, home directory, or groups.sudo usermod -l newname oldname
Example: sudo usermod -l david john
idDisplay user ID (UID) and group ID (GID) information.id username
Example: id john
whoamiShow the currently logged-in user.whoami
whoList all users currently logged into the system.who
wShow logged-in users and their activity.w
lastDisplay login history of users.last
groupsShow groups a user belongs to.groups username
Example: groups john
groupaddCreate a new user group.sudo groupadd groupname
Example: sudo groupadd developers
groupdelDelete a group.sudo groupdel groupname
Example: sudo groupdel developers
usermod -aGAdd a user to a group.sudo usermod -aG groupname username
Example: sudo usermod -aG sudo john
chageSet or check password expiry details for a user.sudo chage -l username
Example: sudo chage -l john
getent passwdList all users on the system.getent passwd
awk -F:Display only the usernames of all users.awk -F: '{print $1}' /etc/passwd
compgen -uShow all system users.compgen -u
sudo visudoEdit sudo privileges for users.sudo visudo
`whowc -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.

Screenshot-2024-09-25-145332

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/passwdfile. 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:

  1. Superuser/root/administrator : Access to all the files on the system.
  2. Normal users : Limited access.

When a new user is created, by default system takes following actions:

  • Assigns UID to the user.
  • Creates a home directory /home/.
  • Sets the default shell of the user to be /bin/sh.
  • Creates a private user group, named after the username itself.
  • Contents of /etc/skel are copied to the home directory of the new user.
  • .bashrc, .bash_profile and .bash_logout are copied to the home directory of new user.These files provide environment variables for this user’s session.

1. Description of contents of /etc/passwd File

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:

  1. Username field
  2. Password field
    • An `x` in this field denotes that the encrypted password is stored in the /etc/shadow file.
  3. The user ID number (UID)
  4. User's group ID number (GID)
  5. Additional information field such as the full name of the user or comment (GECOS)
  6. Absolute path of user’s home directory
  7. Login shell of the user

Syntax:

[username]:[password]:[UID]:[GID]:[GECOS]:[home_dir]:[shell_path]

Example:

2. Description of contents of the /etc/shadow File

This 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:

  1. User name field
  2. Password field
  3. Contains an encrypted password.
    • A blank entry, {:: }, indicates that a password is not required to login into that user’s account.
    • An asterisk, {:*:}, indicates the account has been disabled.
  4. Last Password Change
    • This field denotes the number of days since the date of last password change counted since UNIX time (1-Jan-1970).
  5. The minimum number of days after which the user can change his password.
  6. Password validity
    • Denotes the number of days after which the password will expire.
  7. Warning period
    • Denotes the number of days before the password expiry date, from which the user will start receiving warning notification for password change.
  8. Account validity
    • Denotes the number of days after which the account will be disabled, once the password is expired.
  9. Account disability
    • This field denotes the number of days since which the account had been disabled counted from UNIX time (1-Jan-1970).

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 Administration

Option

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 kavya
-m Option

2. -d Option (Custom Home Directory)

To assign a non-default home directory, use the -d option:

sudo useradd -d /custom/home kavya
-d Option

3. -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.

-s Option

4. -G Option (Add User to Groups)

To add a user to additional groups, use the -G option:

sudo useradd -G sudo,developers kavya
-G Option

5. -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.

-e Option

Conclusion

User 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.


Next Article
Article Tags :

Similar Reads