Chapter 5: Managing Users and Permissions in WSL Ubuntu

Chapter 5: Managing Users and Permissions in WSL Ubuntu

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 newuser to create a user, su - newuser to switch accounts, and sudo deluser username to delete one. To grant sudo privileges, run sudo 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 -l to 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) like chmod 755 for rwxr-xr-x.
  • Ownership and Sudo: Change a file's owner with sudo chown user:group file.txt. The sudo command 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 permissions
  • r-- – group permissions
  • r-- – 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 = 4
  • w = 2
  • x = 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


Leave a Reply

Your email address will not be published. Required fields are marked *