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

FileContainsView With
/etc/passwdUsername, UID, GID, home dir, shell โ€” one line per usercat /etc/passwd
/etc/shadowEncrypted passwords and password aging info โ€” root onlysudo cat /etc/shadow
/etc/groupGroup names, GID, member listcat /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 users

Competition Commands โ€” User Management

bash
# List all users
cat /etc/passwd
getent passwd # same, but works even with LDAP/NIS
# Add a user (creates home dir, sets up defaults)
sudo adduser alice
# Remove a user
sudo deluser bob
sudo deluser --remove-home bob # also deletes /home/bob
# Set or change a password
sudo passwd alice
# Check what groups a user is in
groups alice
id alice

Competition Commands โ€” Group Management

bash
# Create a new group
sudo groupadd physics
# Add a user to a group
sudo gpasswd -a alice physics
# or: sudo usermod -aG physics alice
# Remove a user from a group
sudo gpasswd -d alice physics
# Delete a group
sudo groupdel physics
# List members of a group
getent group physics
members physics # if 'members' package is installed

Check Who Has sudo Access

bash
# Users in the sudo group can use sudo
getent group sudo
# Users in the admin group also typically have sudo
getent 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?

โญ 0 XP๐Ÿ”ฅ 0 days