π Linux User Management (Advanced & Real-World Scenarios)
This guide covers:
β
User creation, management & permissions
β
SSH access control
β
File permissions & access restrictions
β
Monitoring user activity
β
Flags & options for commands
πΉ Real-World Enterprise Scenario
Imagine a company where multiple teams (Admins, Developers, Read-Only Users) access a single Linux server.
Full root access (sudo), can manage users
Can modify project files but not system settings
Can view logs but cannot modify files
πΉ Step 1: Creating Users & Assigning Groups
1.1 Adding Users with Flags
πΉ Create an Admin user (john) with a home directory:
sudo useradd -m -s /bin/bash john
π οΈ Breakdown of Flags:
-m β Creates a home directory (/home/john)
-s /bin/bash β Sets Bash shell for the user
β
Common Issue: User can't login
Solution: Set a password
πΉ Create a Developer (alice):
πΉ Create a Read-Only User (bob):
1.2 Creating & Managing Groups
πΉ Create role-based access groups:
πΉ Add users to their respective groups:
πΉ Check a user's groups:
β
Common Issue: User permissions not working
πΉ Reapply group permissions & restart session:
πΉ Step 2: Managing SSH Access
2.1 Restricting SSH Access by User Role
πΉ Allow only admins to SSH into the server:
Edit SSH config:
Add:
Restart SSH service:
β
Common Issue: SSH Access Denied
πΉ Check SSH logs:
2.2 Setting Up SSH Key Authentication
πΉ Generate SSH key on local machine:
πΉ Copy public key to server (alice user):
β
Common Issue: SSH Permission Denied
πΉ Ensure correct permissions:
πΉ Step 3: Managing File Permissions & Access Control
3.1 Setting Up Role-Based Access for Shared Directory
πΉ Create a project folder for Developers (/opt/project)
π οΈ Breakdown of Permissions:
770 β Developers can read/write, others no access
chown :developers β Assigns group ownership
πΉ Grant Read-Only Users (bob) access to logs only:
β
Common Issue: Developers can't modify files
πΉ Check file ownership:
πΉ Step 4: Monitoring & Restricting Users
4.1 Checking Active Users & Login History
πΉ See currently logged-in users:
πΉ Check login history:
β
Common Issue: Unauthorized login attempts
πΉ Monitor failed login attempts:
4.2 Restricting User Access
πΉ Lock a user account (bob) temporarily:
πΉ Disable interactive login for a user:
πΉ Delete a user (bob) completely:
β
Common Issue: User Cannot Login After Reset
πΉ Re-enable account and reset password:
π Enterprise Setup Summary
β Admins (john) β Full sudo access
β Developers (alice) β Modify project files
β Read-Only (bob) β View logs but no changes
β SSH restricted to Admins only
β Shared directory with correct permissions
β Monitoring & restricting user access
Next: Do you want to automate user management using Ansible or Bash scripts? π
Last updated