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.
06.1 Core Concepts
Section titled “06.1 Core Concepts”Users and Groups
Section titled “Users and Groups”- 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.
UID & GID
Section titled “UID & GID”The Linux kernel tracks users and groups by numeric IDs, not names:
- UID (User ID):
0is alwaysroot. Standard interactive users start at1000(e.g.,1000,1001). System daemon accounts (e.g.,nginx,docker,systemd-resolve) typically use UIDs between1and999. - GID (Group ID): Numeric identifier for groups.
Primary vs Supplementary Groups
Section titled “Primary vs Supplementary 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, ordockergroup).
06.2 Essential Configuration Files
Section titled “06.2 Essential Configuration Files”| 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 |
06.3 User Management Commands
Section titled “06.3 User Management Commands”# Create a new user with home directory (-m) and bash shell (-s)sudo useradd -m -s /bin/bash alice
# Set or change user passwordsudo 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 aliceGroup Management
Section titled “Group Management”# Create a new groupsudo groupadd devops
# Rename a groupsudo groupmod -n engineering devops
# Delete a groupsudo groupdel engineering06.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:
Default Cloud AMI Usernames
Section titled “Default Cloud AMI Usernames”| 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:
Step 1: Connect as the Default Cloud User
Section titled “Step 1: Connect as the Default Cloud User”ssh -i aws-key.pem ubuntu@54.201.10.20Step 2: Create Your Personal User Account
Section titled “Step 2: Create Your Personal User Account”# 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 synStep 3: Provision SSH Key Access
Section titled “Step 3: Provision SSH Key Access”Copy the authorized public keys from the default account to your new personal user:
# Create SSH directory for the new usersudo mkdir -p /home/syn/.ssh
# Copy authorized_keyssudo cp /home/ubuntu/.ssh/authorized_keys /home/syn/.ssh/
# Enforce strict ownership and permissions (MANDATORY)sudo chown -R syn:syn /home/syn/.sshsudo chmod 700 /home/syn/.sshsudo chmod 600 /home/syn/.ssh/authorized_keys[!IMPORTANT] If permissions on
/home/syn/.ssh(mode700) orauthorized_keys(mode600) are too permissive, the SSH daemon’s StrictModes will automatically reject the login withPermission denied (publickey).
Step 4: Verify Personal Login
Section titled “Step 4: Verify Personal Login”Open a new, separate terminal to verify access before closing your active session:
ssh -i aws-key.pem syn@54.201.10.20Test sudo privilege:
sudo whoami# Expected output: root06.6 Identity and Auditing Commands
Section titled “06.6 Identity and Auditing Commands”# Print current active userwhoami
# Display real/effective UID, GID, and all group membershipsidid alice
# Display users currently logged in with active TTYswho
# Detailed view of logged-in users, terminal, remote IP, and running processesw
# Show recent user login history and reboot eventslast -n 15