Linux Users and Groups Management
Linux uses users and groups to control access to files, applications, services, and system resources. Understanding account management is essential for maintaining secure and organized Linux systems.
What are Linux Users?
A Linux user is an account that can interact with the operating system. Each user has an identity, a user ID, a home directory, and permissions that determine what resources they can access.
User Account → UID → Home Directory → Groups → Permissions
What are Linux Groups?
Groups allow administrators to organize users and assign shared access to files and resources. A user can belong to multiple groups.
groups username
id username
Creating a User
The useradd command creates a new Linux user account. Administrators commonly combine it with options for creating a home directory and assigning a login shell.
sudo useradd -m -s /bin/bash alice
sudo passwd alice
Creating a Group
The groupadd command creates a new group that can be used to organize users and manage shared permissions.
sudo groupadd developers
Adding Users to Groups
The usermod command can add a user to supplementary groups. The -aG options are commonly used to preserve existing group memberships while adding another group.
sudo usermod -aG developers alice
id alice
Viewing User Information
The id and getent commands can be used to inspect user and group information.
id alice
getent passwd alice
getent group developers
Linux User and Group Files
| File | Purpose | Example Command |
|---|---|---|
| /etc/passwd | Stores basic account information | cat /etc/passwd |
| /etc/group | Stores group information | cat /etc/group |
| /etc/shadow | Stores password-related account data | sudo cat /etc/shadow |
| /etc/sudoers | Defines sudo privileges | sudo visudo |
Changing User Information
The usermod command can modify account properties such as the login shell, home directory, username, and supplementary groups.
sudo usermod -s /bin/bash alice
sudo usermod -d /home/alice-new -m alice
Deleting a User
The userdel command removes a user account. The -r option can also remove the user's home directory and mail spool, so it should be used carefully.
sudo userdel alice
sudo userdel -r alice
Managing Passwords
The passwd command changes a user's password and can also be used by administrators to manage password-related account settings.
passwd
sudo passwd alice
sudo passwd -l alice
sudo passwd -u alice
Linux User Management Command Table
| Command | Purpose | Example |
|---|---|---|
| useradd | Create a user | sudo useradd -m alice |
| usermod | Modify a user | sudo usermod -aG developers alice |
| userdel | Delete a user | sudo userdel alice |
| groupadd | Create a group | sudo groupadd developers |
| groups | Show group membership | groups alice |
| id | Show user and group IDs | id alice |
| passwd | Manage passwords | sudo passwd alice |
Sudo and Administrative Access
Linux systems commonly use sudo to allow authorized users to run specific commands with elevated privileges. Access should be granted carefully and only when necessary.
sudo command
sudo -l
Example User Management Scenario
Create User → Create Group → Add User to Group → Set Password → Configure Permissions → Test Access
Common User Management Problems
- Incorrect group membership
- Locked user accounts
- Incorrect home directory permissions
- Missing sudo privileges
- Expired passwords
- Incorrect login shell
Common Mistakes to Avoid
- Giving unnecessary sudo privileges
- Deleting users without checking ownership of important files
- Using weak passwords
- Forgetting to remove unused accounts
- Using usermod without preserving existing groups
Advanced Linux Account Concepts
- User and group IDs
- Supplementary groups
- System accounts
- Sudo policies
- Access Control Lists
- Centralized authentication
- Account expiration
Practice Exercises
- Create a test user
- Create a developers group
- Add the user to the group
- Inspect user and group IDs
- Configure a password
- Test sudo permissions
- Remove the test account safely
Conclusion
Linux user and group management provides the foundation for controlling system access. Commands such as useradd, usermod, groupadd, passwd, and sudo help administrators create accounts, organize permissions, and manage privileged access.