- Understanding Linux Users
- Checking Current Users
- Adding New Users
- Modifying User Properties
- Deleting Users
- Locking and Unlocking User Accounts
- Managing User Permissions with Groups
- Viewing and Modifying User Permissions
- Conclusion

Managing users in a Linux environment through the command line is a crucial skill for system administrators and developers alike. While graphical user interfaces (GUIs) simplify many processes, command line proficiency allows for greater control, automation, and efficiency, especially in server environments where a GUI may not be available.
Understanding Linux Users
In Linux, users can be categorized into three types: regular users, system users, and root users. Regular users have limited permissions to perform actions only within their own home directories (typically /home/username). System users, often created upon installation of the OS or specific software, are crucial for running services or software. The root user has the highest level of access and is responsible for system-wide changes and configurations.
Checking Current Users
To view the list of currently logged-in users, the who command is handy. It will display a list of users currently using the system along with their login time and the terminal they are using. For a complete listing of all user accounts on the system, you can check the /etc/passwd file:
cat /etc/passwd
This file contains vital information about users, including username, UID (user ID), GID (group ID), home directory, and default shell.
Adding New Users
Creating a new user can be accomplished with the useradd command. For instance, to add a user named “john”, you can run:
sudo useradd -m john
The -m flag creates a home directory for the new user. You can also specify additional options such as shell and user groups. To set a password for the user, use the passwd command:
sudo passwd john
You will be prompted to enter and confirm the password.
Modifying User Properties
As user needs change, you may want to modify their properties using the usermod command. For example, to add “john” to the “developers” group, you can enter:
sudo usermod -aG developers john
The -aG flags ensure that the user is appended to the specified group without being removed from other groups.
Deleting Users
When a user no longer requires access, it is essential to remove their account properly. You can do this with the userdel command:
sudo userdel john
To also delete the user’s home directory and files, use the -r option:
sudo userdel -r john
This command removes the user’s account and all associated files, which helps keep the system organized.
Locking and Unlocking User Accounts
Sometimes, you might need to temporarily disable a user account without deleting it. You can lock a user account with:
sudo usermod -L john
To unlock the account, use:
sudo usermod -U john
This is particularly useful for managing access during security incidents or when a user is on leave.
Managing User Permissions with Groups
Linux uses a group-based permission model, making effective management of groups essential for maintaining security and access control. You can view a user’s existing groups with the groups command:
groups john
To modify group memberships, remember to use the usermod command as discussed earlier.
Viewing and Modifying User Permissions
To check the permissions for a specific file or directory, the ls -l command will show you the ownership and permission details. Permissions can be modified using the chmod command, for instance:
chmod 755 myfile
This sets the file permissions to allow the owner to read, write, and execute; while allowing the group and others to read and execute only.
Conclusion
Effective management of Linux users via the command line is a vital aspect of system administration. It allows for efficient control of user access, permissions, and overall system security. By mastering commands such as useradd, usermod, and userdel, administrators can maintain a streamlined and secure environment. As you become more comfortable with these commands, you’ll find that managing users can be both straightforward and powerful.