02 Managing Local Users
02 Managing Local Users
CentOS 7
A Comprehensive Tutorial with Labs and Examples
Table of Contents
1. Introduction to User Accounts
2. The id Command
3. Creating User Accounts
4. Managing User Passwords
5. Password Aging and Shadow Data
6. User Account Defaults
7. Modifying and Deleting User Accounts
8. Summary and Key Takeaways
9. Hands-On Labs
2. The id Command
Displays user and group information.
Basic Usage
bash
Copy
Download
id # Shows current user info
id root # Shows info for root
Useful Options
-u Display UID id -u
-g Display GID id -g
Example:
bash
Copy
Download
$ id -Gn tux
tux wheel
3. Creating User Accounts
Basic User Creation
bash
Copy
Download
sudo useradd user1 # Creates user1 with default settings
sudo passwd user1 # Sets password for user1
Example:
bash
Copy
Download
sudo useradd -m -G adm -s /bin/bash user2
Copy
Download
tail -n 1 /etc/passwd # Shows last created user
ls /home # Checks home directory creation
4. Managing User Passwords
Setting Passwords
bash
Copy
Download
sudo passwd user1 # Interactive password setting
Copy
Download
echo "user2:Password123" | sudo chpasswd
Copy
Download
sudo passwd -l user1 # Locks user1
sudo passwd -u user1 # Unlocks user1
Copy
Download
sudo grep user1 /etc/shadow
!! = Locked account
Example:
bash
Copy
Download
sudo chage -M 60 -m 7 -W 7 user1
Copy
Download
sudo grep user1 /etc/shadow
Format: username:password:last_change:min:max:warn:inactive:expire
Copy
Download
sudo useradd -D
Modifying Defaults
Example:
bash
Copy
Download
sudo useradd -D -s /bin/bash
Configuration Files
-c
Comment (Full sudo usermod -c "John Doe" user1
Name)
Example:
bash
Copy
Download
sudo usermod -aG wheel user1 # Grants sudo access
Copy
Download
sudo userdel user1 # Keeps home directory
sudo userdel -r user1 # Deletes home dir & mail spool
Cleaning Up Files:
bash
Copy
Download
sudo find / -uid 1001 -delete # Removes files owned by UID 1001
bash
Copy
Download
Copy
Download
Copy
Download
Copy
Download
id labuser
grep labuser /etc/group
Lab 2: Password Aging Policies
bash
Copy
Download
Copy
Download
bash
Copy
Download
2. Verify deletion.
bash
Copy
Download
ls /home
grep labuser /etc/passwd
Final Notes