Linux

Chapter 5: Managing Users and Permissions in WSL Ubuntu

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 *