AI Reading
Quick summary of this article
Linux is a multi-user operating system, and in WSL Ubuntu, you manage individual user identities, groups, and permissions to control access to files and system resources. The default user created during setup has sudo privileges, allowing administrative tasks. This chapter covers creating and deleting users, adding users to groups, and modifying file access using commands like chmod, chown, and sudo.
- Users and Groups: Each user has an identity, and groups are collections of users sharing permissions. The root user (superuser) has full system control.
- User Management Commands: Use
sudo adduser newuserto create a user,su - newuserto switch accounts, andsudo deluser usernameto delete one. To grant sudo privileges, runsudo usermod -aG sudo newuser. - File Permissions: Every file has read (r), write (w), and execute (x) permissions for three categories: user (owner), group, and others. Use
ls -lto view them. - Changing Permissions with chmod: You can add or remove permissions symbolically (e.g.,
chmod u+x script.sh) or use numeric values (r=4, w=2, x=1) likechmod 755for rwxr-xr-x. - Ownership and Sudo: Change a file's owner with
sudo chown user:group file.txt. Thesudocommand lets authorized users run commands with root privileges, but only members of the sudo group can use it.
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
