Chapter 5: Managing Users and Permissions in WSL Ubuntu
In Linux, every file and process is associated with a user. Understanding how to manage users and control access permissions is crucial for both security and effective system administration.
This chapter introduces Linux users, groups, and permissions in WSL Ubuntu. You’ll learn to manage users, assign privileges, and modify file access rights using commands like chmod, chown, and sudo.
π€ Understanding Users and Groups
Linux systems are multi-user by nature. Hereβs how theyβre structured:
- User: An individual identity (e.g., “umar”)
- Group: A collection of users with shared permissions
- Root: The superuser with full system privileges
Your default WSL user is usually created during the first Ubuntu launch, and it has sudo privileges.
π₯ User Management
π Add a New User
sudo adduser newuser
Youβll be prompted to set a password and fill in optional info.
π Switch User
su - newuser
π See All Users
cut -d: -f1 /etc/passwd
π Add User to Group (e.g., sudo)
sudo usermod -aG sudo newuser
π Delete a User
sudo deluser username
π File and Directory Permissions
Every file has three types of permissions for:
- User (u) β The file owner
- Group (g) β Users in the fileβs group
- Others (o) β Everyone else
Permissions are represented as:
r β read
w β write
x β execute
Example output of ls -l:
-rw-r--r-- 1 umar umar 120 Aug 21 file.txt
-β file type (- = file, d = directory)rw-β user permissionsr--β group permissionsr--β othersβ permissions
π§ Changing Permissions with chmod
π Symbolic Method
chmod u+x script.sh # Give execute permission to owner
chmod g-w file.txt # Remove write from group
chmod o+r file.txt # Add read for others
π Numeric Method
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
Permission values:
r = 4w = 2x = 1
So chmod 754 means:
Owner: rwx (7)
Group: r-x (5)
Others: r-- (4)
π οΈ Change Ownership with chown
Change file owner and group:
sudo chown umar:umar file.txt
Change only the owner:
sudo chown newuser file.txt
π§ββοΈ Working with sudo
sudo (Superuser Do) allows a regular user to run commands with root privileges.
sudo apt update
sudo rm -rf /some/folder
Only users in the sudo group can use sudo. Add someone using:
sudo usermod -aG sudo newuser
π§ͺ Practice Exercise
# Create file and view permissions
touch test.txt
ls -l test.txt
# Change permission
chmod 600 test.txt
chmod +x test.txt
# Create user and assign sudo
sudo adduser devuser
sudo usermod -aG sudo dev
