3.3 KiB
User Management Solutions
This section contains my solutions to various user management scenarios from the practice exercises.
Scenario: Creating Users with Specific Requirements
Original Problem
From Practice Scenarios v3: Create a user named 'john' with a custom shell and home directory.
Environment
- OS Version: Rocky Linux 8.x
- Initial State: No user 'john' exists
- Required Outcome: User 'john' created with specific requirements
Solution Steps
-
Create the user with specific requirements
# Create user with custom home directory sudo useradd -m -d /custom/home/john -s /bin/bash john # Set password sudo passwd johnThis creates the user 'john' with a custom home directory and bash shell
-
Verify user creation
# Check user entry in /etc/passwd grep john /etc/passwd # Verify home directory ls -la /custom/home/john
Key Learnings
- Understanding of useradd command options
- Importance of verifying user creation
- Best practices for user management
Skills Demonstrated
- User Account Management
- Command Line Proficiency
- Security Best Practices
- System Verification
Scenario: Creating Users with Specific Requirements
Original Problem
- Create a new user called 'analyst1' with home directory '/home/analyst1'
- Create a group called 'datateam'
- Add 'analyst1' to 'datateam'
- Create a directory '/data/reports' owned by 'datateam' with SGID set
- Ensure members of 'datateam' can read/write, others can only read
- Set password expiry for 'analyst1' to 90 days
Environment
- OS Version: RHEL 9.5
- Initial State: No user 'analyst1' exists
- Required Outcome: User 'analyst1' created with specific requirements
Solution Steps
-
Step 1 - Create the user 'analyst1'
sudo useradd -m -d /home/analyst1 analyst1This creates the user 'analyst1' with a home directory '/home/analyst1'
-
Step 2
sudo groupadd datateamThis creates the group 'datateam'
-
Step 3 - Add 'analyst1' to 'datateam'
sudo usermod -aG datateam analyst1This adds 'analyst1' to the 'datateam' group
-
Step 4 - Create the directory '/data/reports' owned by 'datateam' with SGID set
sudo mkdir -p /data/reports sudo chown :datateam /data/reports sudo chmod 2775 /data/reportsThis creates the directory '/data/reports' owned by 'datateam' with SGID set
-
Step 5 - Ensure members of 'datateam' can read/write, others can only read
sudo chmod 2775 /data/reportsThis ensures members of 'datateam' can read/write, others can only read
-
Step 6 - Set password expiry for 'analyst1' to 90 days
sudo chage -E $(date -d '90 days' +%Y-%m-%d) analyst1This sets the password expiry for 'analyst1' to 90 days
Verification
Commands used to verify the solution works correctly
Key Learnings
- Understanding of useradd, groupadd, usermod, mkdir, chown, chmod, chage commands
- Importance of verifying user creation
- Importance of setting password expiry
Additional Notes
[NOTE] This scenario is a good example of how to create a user with a specific home directory, add them to a group, create a directory owned by the group with SGID set, and set password expiry.