While many enterprise environments rely on dedicated systems for identity management, understanding the fundamentals of Linux user management directly on a single machine is a crucial skill. Several utilities serve as the command-line tool for managing accounts in Linux, allowing for efficient administration from the terminal.
Adding Users
To create a new user, you can use the useradd command. It is a low-level utility that creates a new user account based on default values found in /etc/default/useradd. While some systems also offer adduser, a more interactive and user-friendly script, useradd is the universal standard.
sudo useradd bob
Executing this command adds an entry for the user "bob" in the /etc/passwd file, sets up default group memberships, and creates a corresponding entry in the /etc/shadow file to store password information securely.
Removing Users
To remove a user account, you can use the userdel command. This command effectively reverses the changes made by useradd by removing the user's entries from the system account files.
sudo userdel bob
By default, this command may not remove the user's home directory. You can use the -r flag (userdel -r bob) to ensure the home directory and mail spool are also deleted.
Changing Passwords
The passwd command is used to set or change a user's password. A regular user can run this command to change their own password. The root user can run it to change any user's password.
passwd bob
When run by an administrator, the system will prompt for a new password for the specified user without asking for the old one. This is a fundamental task in Linux user management.