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 / deluserto create or delete users - Use
addgroup / delgroupto manage groups - Use
usermod -aGto add users to groups - Use
ls -lto view file permissions - Use
chmodto change permissions andchownto 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.
