Linux

Chapter 12: User and Permission Management in WSL Ubuntu

Chapter 12: User and Permission Management in WSL Ubuntu

Managing users and file permissions is essential for system security and proper access control in Linux. WSL Ubuntu allows you to create users, assign groups, and control file permissions easily.

In this chapter, you’ll learn how to create users, manage groups, and control file permissions using essential Linux commands.

๐Ÿ‘ค Managing Users

๐Ÿ“Œ Create a New User

sudo adduser username

Example:

sudo adduser umar

This will prompt for password and optional details.

๐Ÿ“Œ Delete a User

sudo deluser username

To remove home directory as well:

sudo deluser --remove-home username

๐Ÿ“Œ Modify a User

sudo usermod -aG groupname username

Adds a user to a group (append -aG to avoid removing from other groups).

๐Ÿ‘ฅ Managing Groups

๐Ÿ“Œ Create a Group

sudo addgroup groupname

๐Ÿ“Œ Delete a Group

sudo delgroup groupname

๐Ÿ“Œ View Groups for a User

groups username

๐Ÿ”‘ File Permissions

๐Ÿ“Œ View Permissions

ls -l filename

Example output:

-rw-r--r-- 1 umar users 1024 Aug 21 10:00 file.txt
  • Owner: umar
  • Group: users
  • Permissions: rw-r--r-- (read/write for owner, read for group and others)

๐Ÿ“Œ Change File Ownership

sudo chown user:group filename

Example:

sudo chown umar:users file.txt

๐Ÿ“Œ Change File Permissions

chmod 755 script.sh
  • 7 โ†’ read/write/execute (owner)
  • 5 โ†’ read/execute (group)
  • 5 โ†’ read/execute (others)

๐Ÿงช Practice Exercises

# Create a user
sudo adduser john

# Add user to a group
sudo usermod -aG sudo john

# View groups for a user
groups john

# Change file ownership
sudo chown john:users file.txt

# Change file permissions
chmod 644 file.txt
chmod 755 script.sh

โœ… Summary

  • Use adduser / deluser to create or delete users
  • Use addgroup / delgroup to manage groups
  • Use usermod -aG to add users to groups
  • Use ls -l to view file permissions
  • Use chmod to change permissions and chown to change ownership
  • Proper user and permission management ensures system security

โ–ถ๏ธ Coming Up Next

Chapter 13 โ€“ Scheduled Tasks and Cron Jobs in WSL Ubuntu
Learn how to automate tasks using cron and schedule scripts to run at specific intervals.

Leave a Reply

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