Overview
This guide covers essential Linux commands for user and group management, which are fundamental for system administration and security. Whether you’re managing a single server or multiple systems, these commands will help you maintain user accounts efficiently.
Note
Most of these commands require sudo (superuser) privileges. If you’re not in the sudoers group, ask your system administrator to grant access before proceeding.
User Management
List All Users
Display all user accounts on the system:
cat /etc/passwdEach line shows: username, password hash, UID, GID, full name, home directory, and login shell.
Add a New User
Create a new user account with a home directory:
sudo adduser usernameThis command will prompt you to:
- Set a password
- Confirm the password
- Enter user information (name, room number, phone, etc.) — leave blank if not needed
Add User to Sudo Group
Grant administrative privileges to an existing user:
sudo usermod -aG sudo usernameThe -aG flag means: -a (append) and -G (groups). The user is added to the sudo group without removing from other groups.
Warning (Sudo Access)
Only add trusted users to the sudo group, as they gain root-level access. Always verify before granting sudo privileges.
Delete a User
Remove a user account while keeping their home directory:
sudo deluser usernameDelete User and Home Directory
Completely remove a user and all their files:
sudo deluser --remove-home usernameDanger (Permanent Deletion)
This command permanently deletes the user’s home directory and all files. There is no undo — ensure you have backups before proceeding.
Group Management
List All Groups
Display all groups on the system:
cat /etc/groupEach line shows: group name, password field, GID, and member list.
Create a New Group
sudo addgroup groupnameAdd User to Group
sudo usermod -aG groupname usernameRemove User from Group
sudo deluser username groupnameFile Permissions and Ownership
Change Group Ownership
Assign a group to a directory and all its contents recursively:
sudo chgrp -R groupname directorynameThe -R flag applies the change recursively to all files and subdirectories.
Tip
For example, to give the www-data group ownership of a web directory:
sudo chgrp -R www-data /var/www/mysiteChange File Ownership
Change both user and group ownership:
sudo chown -R username:groupname directorynameExample:
sudo chown -R ubuntu:ubuntu /home/ubuntu/myprojectView File Permissions
ls -l filenameOutput shows permissions, owner, group, size, date, and filename.
Summary
These fundamental commands are essential for managing users, groups, and permissions in Linux systems. Regular practice will make these operations second nature for system administration tasks.
To make directory read write access to group
sudo chmod g+rwx -R directoryname