Linux User Management Cheat Sheet
Category : Cheat Sheets
This is my cheat sheet on Linux user administration covering functions such as adding, and removing users and assigning them to groups.
Add a new Linux user
Use the useradd command to add a new user.
Change a users password
The user account is locked until you set a password with the passwd command.
Add user to group – new user
If you are adding a new user, you can add it to a group in the same command. This command will create a user of [USERNAME] in group [GROUPNAME].
useradd -G [GROUPNAME] [USERNAME]
Add user to group – existing user
If the user already exists, you can add it to an existing group with the usermod command.
usermod -a -G [GROUPNAME] [USERNAME]
Delete a user
Run the userdel command to remove an existing Linux user.
View existing users and groups
Run the below cat command to view existing Linux users. You sill see the user names and user IDs of all users on your server.
cat /etc/passwd | sort
Use this cat command to view the existing Linux groups.
cat /etc/group | sort
Change a users home directory location
You can change the users home directory with the usermod command.
usermod -d -m [NEW_DIRECTORY] [USERNAME]
Change a users UID
Use the usermod -u command to change the user ID of a user.
usermod -u [UID] [USER_NAME]