Linux User Management: useradd, usermod and passwd
Linux user management runs on three commands: useradd creates a user, passwd sets the password, and usermod changes groups and account settings afterwards. These need root privileges, so prefix them with sudo.
Create a user
useradd creates the account. Add -m to create the home directory and -s to set the login shell.
Set the password
A new user has no password until you run passwd. It asks for the password twice and updates the stored hash in /etc/shadow.
Add a user to a group
Groups control shared permissions. Add a user to the sudo group to grant admin rights, or to a project group for shared files. Use -aG (append to group) and never forget the -a — without it usermod replaces all group memberships.
List and check users and groups
Check what groups a user belongs to with groups, and see all accounts in /etc/passwd.
Delete or lock a user
To temporarily block logins without deleting the account, lock the password with passwd -l. To remove the account and its home directory, use userdel -r.
Combine user management with chmod to control what each user and group can do. See useradd for the full option list.
Keep learning
Related guides: Linux chmod Command: A Complete Permissions Guide · How to Set Up SSH Keys for Passwordless Login · Linux Environment Variables: How to Set and Use Them. Read all tutorials on the Learn Linux blog.