Ubuntu Security ยท 4.1
๐ค User & Group Management
Add, remove, and audit user accounts the right wayโฑ ~3 min
User and group management on Ubuntu is done primarily through the command line. The key files are /etc/passwd (user info), /etc/shadow (encrypted passwords), and /etc/group (group membership).
Key User Files
| File | Contains | View With |
|---|---|---|
| /etc/passwd | Username, UID, GID, home dir, shell โ one line per user | cat /etc/passwd |
| /etc/shadow | Encrypted passwords and password aging info โ root only | sudo cat /etc/shadow |
| /etc/group | Group names, GID, member list | cat /etc/group |
Reading /etc/passwd
bash
# Format: username:password:UID:GID:comment:home:shell# Example:alice:x:1001:1001:Alice Smith:/home/alice:/bin/bash# ^ ^ shell โ /bin/false or /sbin/nologin# means password is in /shadow means account cannot log in interactively # UIDs to know:# 0 = root (superuser)# 1-999 = system accounts (daemons, services)# 1000+ = human usersCompetition Commands โ User Management
bash
# List all userscat /etc/passwdgetent passwd # same, but works even with LDAP/NIS # Add a user (creates home dir, sets up defaults)sudo adduser alice # Remove a usersudo deluser bobsudo deluser --remove-home bob # also deletes /home/bob # Set or change a passwordsudo passwd alice # Check what groups a user is ingroups aliceid aliceCompetition Commands โ Group Management
bash
# Create a new groupsudo groupadd physics # Add a user to a groupsudo gpasswd -a alice physics# or: sudo usermod -aG physics alice # Remove a user from a groupsudo gpasswd -d alice physics # Delete a groupsudo groupdel physics # List members of a groupgetent group physicsmembers physics # if 'members' package is installedCheck Who Has sudo Access
bash
# Users in the sudo group can use sudogetent group sudo # Users in the admin group also typically have sudogetent group admin # View sudoers file (be careful, use visudo to edit)sudo cat /etc/sudoers๐ SecurityCompetition: compare the list of users in the 'sudo' group against the scenario's list of authorized administrators. Remove unauthorized users from the sudo group with: sudo gpasswd -d USERNAME sudo
๐ง Quick Checkfirst try = +5 XP
How do you remove a user from the sudo group on Ubuntu?
๐ฎ Practice what you learned
โญ 0 XP๐ฅ 0 days