Networking and System AdministrationUnit 311 min read
User & Group Management: Roles, Permissions & Linux Commands
Unit 3 of Networking and System Administration covers user/group creation, permission models (RWX), ownership, ACLs, and Linux commands (useradd, usermod, chmod, chown) with real-world examples from Nepali apps like eSewa and Ncell.
Core Concepts
1. User Accounts: Identity and Access
Every system resource (files, processes, networks) must be tied to an identity. In Linux/Unix, this is the user account, which:
- Authenticates the user (via password or SSH keys).
- Tracks resource usage (CPU, memory, disk quotas).
- Enforces least-privilege access (users get only the permissions they need).
stateDiagram-v2
[*] --> User:Logs in via SSH
User:Logs in via SSH --> Auth:Verifies Public Key
Auth:Verifies Public Key --> Session:Creates Shell
Session:Creates Shell --> Process:Runs 'esewa-transfer'
Process:Runs 'esewa-transfer' --> [*]
Process:Runs 'esewa-transfer' --> Log:Writes to /var/log/esewa
Log:Writes to /var/log/esewa --> [*]eSewa’s SSH key authentication flow (simplified)Real-world tie-in:
- eSewa: When you log in to pay bills, eSewa’s backend checks your user account (stored in a database) to verify you’re authorized to transfer money from your linked bank account. The system uses role-based access control (RBAC): a "customer" role can only view/transfer their own funds, while an "admin" can modify any account.
2. Groups: Organizing Permissions
Groups let you assign permissions to multiple users at once. For example:
- Developers in a team all need read/write access to
/var/www/project/. - Finance staff in a bank need access to ledger files but not customer data.
Key commands:
| Command | Purpose |
|---|---|
groupadd |
Creates a new group (e.g., groupadd developers). |
usermod -aG |
Adds a user to a group (e.g., usermod -aG developers alice). |
groups |
Lists all groups a user belongs to. |
Worked Example:
At Ncell, customer support agents are added to the support_team group. This group has read-only access to call logs but write access to ticket databases. The command to add an agent named ram to this group:
sudo usermod -aG support_team ram
3. File Permissions: RWX Model
Linux uses a 3-digit octal notation (e.g., 755) to represent permissions for:
- Owner (user): Read (4), Write (2), Execute (1).
- Group: Same as owner.
- Others: Public access.
Octal to Symbolic Conversion:
| Octal | Symbolic | Meaning |
|---|---|---|
| 7 | rwx | Read, Write, Execute |
| 5 | r-x | Read, Execute (no Write) |
| 4 | r-- | Read-only |
| 0 | --- | No permissions |
Worked Example:
A Daraz order queue script (/var/www/daraz/process_orders.sh) must:
- Be executable by the
ordersgroup (to run the script). - Be readable by the
auditgroup (to log orders). - Be inaccessible to others.
Solution:
chmod 750 /var/www/daraz/process_orders.sh.
4. Ownership and ACLs
- Ownership: Files/folders have an owner (user) and group. Change with:
chown user:group file # e.g., chown alice:developers report.txt - Advanced Permissions (ACLs): Fine-grained control beyond RWX. Example:
setfacl -m u:bob:rwx /secret/project # Grants Bob RWX even if he’s not in the group.
Real-world tie-in:
- NEPSE (Nepal Stock Exchange): Shareholder records are stored in files owned by the
compliancegroup. Only theauditoruser (outside this group) needs read-only access during inspections. ACLs are used to grant this without adding the auditor to the group:setfacl -m u:auditor:r /data/shareholders/2023.csv
5. Special Permissions: SUID, SGID, Sticky Bit
| Permission | Effect | Example Use Case |
|---|---|---|
| SUID | Runs a file as its owner, not the user. | /usr/bin/passwd (lets users change their password). |
| SGID | Runs a file as its group owner; preserves group ownership on dirs. | Shared folders where all group members can add files. |
| Sticky Bit | Only the owner can delete files in a directory (even if others have write). | /tmp (prevents users from deleting each other’s files). |
Worked Example:
In Khalti’s backend, the /usr/bin/transfer script (used to move money between accounts) must run with the bank’s admin privileges, not the customer’s. This is achieved with SUID:
chmod 4755 /usr/bin/transfer # SUID bit set (4).
6. User Management Commands
| Command | Purpose |
|---|---|
useradd -m username |
Creates a user with a home directory (-m). |
passwd username |
Sets/changes a user’s password. |
usermod -l old new |
Renames a user (e.g., usermod -l john doe). |
userdel -r username |
Deletes a user and their home directory (-r). |
id username |
Shows UID, GID, and groups for a user. |
su - username |
Switches to another user (requires their password). |
Worked Example:
At NTC (Nepal Telecom), a new technician sita is hired. The admin runs:
sudo useradd -m -G tech_support sita
sudo passwd sita
This creates a home directory (/home/sita) and adds her to the tech_support group.
7. Shadow Passwords and /etc/ Files
/etc/passwd: Stores user info (UID, home dir, shell) in plaintext.alice:x:1001:1001:Alice Smith:/home/alice:/bin/bash/etc/shadow: Stores encrypted passwords and account expiry details (accessible only by root).alice:$6$rounds=5000$hashedpassword...:19043:0:99999:7:::/etc/group: Lists groups and their members.developers:x:1002:alice,bob,carol
In the Real World
- eSewa:
- Idea Used: Role-Based Access Control (RBAC).
- How: When you log in, eSewa’s backend checks your user role (e.g., "customer" or "merchant"). A customer can only view/transfer their money, while a merchant can only access their shop’s transactions. The system uses Linux groups internally to enforce these rules on database files (e.g.,
/var/lib/esewa/transactions/is owned by themerchantsgroup).
Ncell Customer Support:
- Idea Used: Group Permissions + ACLs.
- How: Support agents are added to the
support_teamgroup, which has read/write access to call logs (/var/log/ncell/calls/). However, the audit group needs read-only access to these logs for compliance. Instead of adding the audit team tosupport_team, Ncell uses ACLs:setfacl -m g:audit:r-x /var/log/ncell/calls/
Pathao Driver App:
- Idea Used: SUID for Privileged Operations.
- How: When a driver updates their vehicle details in the app, the backend runs a script (
/usr/bin/update_driver_vehicle) that must access the database as thepathao_adminuser (not the driver). The script has SUID set:
This ensures the script runs with admin privileges while the driver’s app interacts with it normally.chmod 4755 /usr/bin/update_driver_vehicle
Common Pitfalls and Best Practices
❌ Avoid These Mistakes
- Over-permissive folders: Setting
777(world-writable) on/etc/or/home/. - Orphaned users: Deleting users without removing their files (
userdel -r). - Hardcoded passwords: Storing passwords in scripts (use
sudoor SSH keys instead).
✅ Follow These Rules
- Least privilege: Give users only the permissions they need (e.g.,
644for config files). - Regular audits: Use
sudo grep "777" / -Rto find over-permissive files. - Use
visudo: Always edit/etc/sudoerswithvisudoto avoid syntax errors.
Exam Tip
This unit is heavily tested in TU exams with:
- Command-based questions (e.g., "Write the command to give the
financegroup read access to/var/accounts/").- Focus on:
chmod,chown,setfacl,usermod,useradd.
- Focus on:
- Scenario-based questions (e.g., "A bank’s loan processing script must run as the
adminuser. How would you configure this?").- Focus on: SUID, SGID, sticky bit, and real-world examples (like Ncell or eSewa).
- Permission calculations (e.g., "What does
chmod 640mean in symbolic form?").- Focus on: Octal to symbolic conversion and RWX for user/group/others.
- Diagram questions (e.g., "Draw the permission bits for a file with
rwxr-x---").- Focus on: Visualizing permissions in tables or octal notation.
Pro Tip:
- Memorize the 3 key commands:
chmod,chown, andsetfacl. - Practice worked examples with Nepali companies (e.g., Daraz order queues, NEPSE shareholder files).
- For scenario questions, always ask:
- Who needs access? (User/Group/Others)
- What level of access? (Read/Write/Execute)
- Is SUID/SGID needed? (For privileged operations)
Based on the TU BITM syllabus for Networking and System Administration (IT271), unit 3.
Discussion
Loading…