Skip to content

3.1 User and Group Management

Authentication in Linux revolves around three plain text files in /etc.

FileContainsPermissions
/etc/passwdUser info (Shell, Home dir, UID).Readable by anyone (644).
/etc/shadowEncrypted passwords.Readable only by root (600/640).
/etc/groupGroup memberships.Readable by anyone (644).

(See [[/en/module-2/4-permissions|Permission Management]] for details on 644/600 modes)

Create, modify, and delete users.

# Create a user named 'anna' with a home directory (-m)
sudo useradd -m -s /bin/bash anna

# Set or change password
sudo passwd anna

# Modify: Add 'anna' to 'developers' group (append mode -aG)
sudo usermod -aG developers anna

# Lock account (disable login)
sudo usermod -L anna

```bash
# Delete user (and their home directory)
sudo userdel -r anna

The root user is the system administrator with unlimited privileges.

Run a single command with root privileges. Safe and logged.

  • Usage: sudo [command]
  • Config: /etc/sudoers (Edit with visudo).

Switch to another user account (default is root).

  • su: Switch to root (keeps current environment variables).
  • su -: Switch to root and load root’s environment (recommended).
  • su - anna: Switch to user ‘anna’.
# Create a new group
sudo groupadd developers

# Delete a group
sudo groupdel developers
  1. New Recruit:
    • Create a new user intern.
    • Assign them a password.
    • Verify their entry in /etc/passwd.
  2. Group Work:
    • Create a group called ops.
    • Add your current user and the intern user to this group.
    • Verify with the groups command (e.g., groups intern).
  3. Cleanup:
    • Delete the intern user and their home directory.
    • Delete the ops group.