Skip to content

06. Users & Groups

Linux is fundamentally a multi-user operating system. Understanding user lifecycles, group inheritance, and user provisioning on physical servers and cloud instances is essential for managing permissions, running secure containers, and auditing access.

  • Users: Entities (humans or background system services) that execute processes and own files.
  • Groups: Logical collections of users that simplify administration by allowing permissions to be granted collectively.

The Linux kernel tracks users and groups by numeric IDs, not names:

  • UID (User ID): 0 is always root. Standard interactive users start at 1000 (e.g., 1000, 1001). System daemon accounts (e.g., nginx, docker, systemd-resolve) typically use UIDs between 1 and 999.
  • GID (Group ID): Numeric identifier for groups.
  • Primary Group: Assigned to the user in /etc/passwd. When a user creates a new file, the file automatically inherits the user’s primary group.
  • Supplementary (Secondary) Groups: Additional groups assigned to expand user privileges (e.g., membership in the sudo, wheel, or docker group).

| File | Purpose | Sample Entry | |||| | /etc/passwd | Account definitions, shell, home dir, UID/GID | alice:x:1001:1001:Alice Smith:/home/alice:/bin/bash | | /etc/shadow | Encrypted password hashes, aging, and expiration | alice:$6$xyz...:19640:1:90:7::: | | /etc/group | Group definitions and member lists | docker:x:998:alice,bob | | /etc/gshadow | Secure group passwords and group admins | docker:!::alice,bob |

Terminal window
# Create a new user with home directory (-m) and bash shell (-s)
sudo useradd -m -s /bin/bash alice
# Set or change user password
sudo passwd alice
# Modify user: Append (-a) user to supplementary group (-G)
# WARNING: Always use -a with -G, or you will remove the user from all other groups!
sudo usermod -aG sudo alice
# Delete a user and purge their home directory and mail spool (-r)
sudo userdel -r alice
Terminal window
# Create a new group
sudo groupadd devops
# Rename a group
sudo groupmod -n engineering devops
# Delete a group
sudo groupdel engineering

06.4 User Provisioning on Cloud Servers (AWS EC2 / GCP / Azure)

Section titled “06.4 User Provisioning on Cloud Servers (AWS EC2 / GCP / Azure)”

When provisioning cloud instances from official AMIs, you initially connect using a distribution-specific default administrative account:

| Distribution | Default AMI User | Administrative Group | |||| | Ubuntu | ubuntu | sudo | | Amazon Linux (AL2 / AL2023) | ec2-user | wheel | | Debian | admin (or debian) | sudo | | RHEL / Rocky / AlmaLinux | ec2-user (or cloud-user) | wheel | | CentOS | centos (or ec2-user) | wheel | | Fedora | fedora (or ec2-user) | wheel |

06.5 Production Walkthrough: Creating a Personal Admin User

Section titled “06.5 Production Walkthrough: Creating a Personal Admin User”

In enterprise production, team members should never share the default ubuntu or ec2-user account. Shared accounts destroy auditability. Follow this standard provisioning pattern:

Terminal window
ssh -i aws-key.pem ubuntu@54.201.10.20
Terminal window
# Create user 'syn'
sudo adduser syn
# Grant administrative privileges:
# On Debian / Ubuntu:
sudo usermod -aG sudo syn
# On RHEL / Alma / Rocky:
sudo usermod -aG wheel syn

Copy the authorized public keys from the default account to your new personal user:

Terminal window
# Create SSH directory for the new user
sudo mkdir -p /home/syn/.ssh
# Copy authorized_keys
sudo cp /home/ubuntu/.ssh/authorized_keys /home/syn/.ssh/
# Enforce strict ownership and permissions (MANDATORY)
sudo chown -R syn:syn /home/syn/.ssh
sudo chmod 700 /home/syn/.ssh
sudo chmod 600 /home/syn/.ssh/authorized_keys

[!IMPORTANT] If permissions on /home/syn/.ssh (mode 700) or authorized_keys (mode 600) are too permissive, the SSH daemon’s StrictModes will automatically reject the login with Permission denied (publickey).

Open a new, separate terminal to verify access before closing your active session:

Terminal window
ssh -i aws-key.pem syn@54.201.10.20

Test sudo privilege:

Terminal window
sudo whoami
# Expected output: root
Terminal window
# Print current active user
whoami
# Display real/effective UID, GID, and all group memberships
id
id alice
# Display users currently logged in with active TTYs
who
# Detailed view of logged-in users, terminal, remote IP, and running processes
w
# Show recent user login history and reboot events
last -n 15