User management is a core function of Linux system administration. It controls system access, enforces security, and ensures users have the correct privileges for their tasks. Linux supports multi-user environments, making it ideal for everything from personal laptops to large enterprise systems. Efficient user management:
Linux systems typically support up to 60,000 users, making them suitable for large-scale use.
Admins manage users by creating, modifying, and deleting accounts, setting permissions, and enforcing access policies. This ensures users can perform tasks without compromising system integrity.
Types of Users in LinuxLinux is a multi-user operating system, meaning multiple users can access and operate the system simultaneously. Each user type serves a specific purpose and has different levels of access and control.
Below are the main types of users you will encounter in Linux:
User Type Description Root (Superuser) Full system control. Can install software, change config files, and delete anything. Powerful but risky. Regular User Limited access. Can create files, run applications, but not modify system-level settings. Sudo User Regular user with temporary admin rights via thesudo
command. Common in modern systems. System/Service Account Non-human accounts used by services (e.g., mysql
, nginx
). Limited privileges. Guest User Temporary users with minimal privileges. Changes are not saved after logout. User Groups
A user group is a collection of users. If you give permission to a group, all users in that group get the same access. This makes it easier to manage file and system permissions for many users at once.
1. Primary Group (Default for files)Check Primary Group:
id raj
Output:
Here, gid=1000(raj)
means the primary group of user raj
is raj
.
Add User to a Secondary Group:
sudo usermod -aG developers raj
raj
to the developers
group.Check Group Memberships:
groups raj
Output:
This shows that user raj
is part of two groups:
raj
developers
These files are essential for managing users, groups, and permissions on a Linux system, and they play a key role in ensuring security and efficient system administration.
The following are different user management files in linux:
User Information/etc/passwd:
Stores basic details of all user accounts including:
/etc/shadow:
Stores encrypted user passwords and password-related settings:
/etc/group
: Defines all groups in the system and user memberships:
/etc/gshadow
: Secure counterpart to /etc/group
, storing:
/etc/sudoers
: Manages sudo access for users and groups:
sudo
command/etc/skel/
: Directory containing default configuration files copied to a new user’s home directory:
.bashrc
, .profile
, etc./var/log/auth.log
: Records authentication-related events:
sudo
commandThe below are some important user account management commands:
1. List all usersTo list all the users in Linux, use the awk
command with the -F
option. This will access the /etc/passwd
file and print only the first column, which contains the usernames.
awk -F':' '{ print $1}' /etc/passwd2. Get User ID
The id
command provides the user ID (UID) of any given username. This ID is also the group ID (GID) of the user by default.
id username
Example: id test
3. Add a UserThe useradd
command creates a new user in the system. The user will be assigned an automatic ID based on the system's settings.
useradd username
Example: sudo useradd geeks
4. Assign a PasswordThe passwd
command is used to assign a password to the user. After entering the command, you will be prompted to input a new password for the user.
passwd username
Example: sudo passwd geeks
5. Accessing a User Configuration FileTo view user details from the /etc/passwd
file, use the cat
command. This file contains user account information like UID, GID, home directory, and login shell.
cat /etc/passwd
This commands prints the data of the configuration file. This file contains information about the user in the format.
username : x : user id : user group id : : /home/username : /bin/bash
Now we will go through the commands to modify information.
Modify User InformationSystem administrators often need to update user account settings. Below are common usermod
and userdel
commands used to modify user accounts.
To change the user ID (UID) of an existing user, use the usermod
command with the -u
option.
usermod -u new_id username
This command can change the user ID of a user. The user with the given username will be assigned with the new ID given in the command and the old ID will be removed.
Example: sudo usermod -u 1982 test
2. Change Group IDTo modify the group ID (GID) of a user or move a user to another group, use the usermod
command with the -g
option.
usermod -g new_group_id username
This command can change the group ID of a user and hence it can even be used to move a user to an already existing group. It will change the group ID of the user whose username is given and sets the group ID as the given new_group_id.
Example: sudo usermod -g 1005 test
3. Change Login NameTo change a user's login name, use the usermod
command with the -l
option.
usermod -l new_login_name old_login_name
Example: sudo usermod -c John_Wick John_Doe
4. Change Home DirectoryTo change a user's home directory, use the usermod
command with the -d
option. You can specify the new path for the home directory.
usermod -d new_home_directory_path username
Example: usermod -d new_home_directory test
5. Delete a UserThe userdel
command removes a user from the system. Use the -r
option to also delete the user's home directory. If the user is part of any group, you must remove them from the group before deletion.
userdel -r username
Example: sudo userdel -r new_geeks
Common Issues in User Management in LinuxManaging users in Linux can present various challenges that impact system security and efficiency. The below are some common issues and strategies to address them:
1. Forgotten PasswordsUsers may forget their passwords, leading to access issues.
Solution: Administrators can reset passwords using the passwd
command.
sudo passwd username
This command prompts for a new password, restoring user access.
2. Account LockoutsMultiple failed login attempts can lock user accounts.
Solution: Unlock accounts using the usermod
command:
sudo usermod -U username
This command unlocks the specified user account.
3. Security VulnerabilitiesOutdated systems can be susceptible to security threats.
Solution: Keep the system updated with the latest patches using the package manager:
sudo apt update && sudo apt upgrade
Regular updates enhance system security.
4. Permission ErrorsIncorrect file or directory permissions can restrict user access.
Solution: Adjust permissions using chmod
and chown
:
sudo chmod 755 /path/to/directory
sudo chown user:group /path/to/file
Proper permissions ensure appropriate access levels.
5. Misconfigured Group MembershipsUsers may lack necessary group memberships, limiting access.
Solution: Add users to groups with usermod
:
sudo usermod -aG groupname username
This command appends the user to the specified group.
6. Privilege Escalation RisksImproper configurations can allow unauthorized privilege escalation.
Solution: Review and edit the /etc/sudoers
file carefully, preferably using visudo
to prevent syntax errors.
sudo visudo
Ensure only authorized users have elevated privileges.
7. Misconfigured User Management FilesErrors in critical files like /etc/passwd
and /etc/shadow
can disrupt user management.
Solution: Use commands like vipw
and vigr
to safely edit these files:
sudo vipw
sudo vigr
These commands lock the files during editing, preventing concurrent modifications.
Also read:
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