Permissions and Users
Understand file permissions, chmod, chown, sudo, and user management.
ls -l and chmod to practice.What You'll Learn
- Reading the rwxr-xr-x permission string
- chmod โ changing permissions (numeric & symbolic)
- chown โ changing file ownership
- sudo, user management, and SSH key permissions
Understanding File Permissions
Every file and directory in Linux has three permission sets for three types of users:
๐ Real-World Analogy: Think of permissions like access cards in an office building. The owner (employee) has their own office key. The group (department) has a floor access card. Others (visitors) have a lobby pass. Each level gives different access.
$ ls -l -rwxr-xr-- 1 alice devs 2048 Mar 18 deploy.sh โโโ โโโ โโโ โโโ โโโ โโโ Others: r-- (read only) โโโ โโโโโ Group: r-x (read + execute) โโโโโโโ Owner: rwx (read + write + execute)
| Permission | Letter | Octal | Meaning |
|---|---|---|---|
| Read | r | 4 | View contents |
| Write | w | 2 | Modify contents |
| Execute | x | 1 | Run as program |
| None | - | 0 | No access |
Octal notation adds the values: rwx = 4+2+1 = 7, r-x = 4+0+1 = 5, r-- = 4+0+0 = 4. So rwxr-xr-- = 754.
Reading Permissions
Understand the permission string and common permission sets.
// File Permissions โ simulated
console.log("=== Understanding Permissions ===");
console.log("$ ls -l script.sh");
console.log("-rwxr-xr-- 1 alice devs 1024 Mar 18 script.sh");
console.log();
console.log("Breaking down: -rwxr-xr--");
console.log(" - = file type (- file, d directory, l link)");
console.log(" rwx = Owner permissions (read, write, execute)");
console.log(" r-x = Group permissions (read, -, execute)");
console.log(" r-- = Others permissions (read, -, -)");
console.log(
...Changing Permissions and Ownership
chmod โ Two Modes
# Numeric (octal) โ set exact permissions $ chmod 755 script.sh # rwxr-xr-x $ chmod 644 config.json # rw-r--r-- $ chmod 600 .env # rw------- (secrets!) # Symbolic โ add/remove specific permissions $ chmod +x deploy.sh # Add execute for everyone $ chmod u+w,g-w file.txt # Add write for owner, remove for group $ chmod -R 755 public/ # Recursive for directories
chown โ Change Ownership
$ sudo chown alice file.txt # Change owner $ sudo chown alice:developers dir/ # Change owner and group $ sudo chown -R www-data:www-data /var/www/ # Recursive
โ ๏ธ Common Mistake
SSH keys (~/.ssh/id_rsa) MUST be chmod 600. SSH will refuse to use keys with overly permissive settings. This is the #1 SSH troubleshooting issue.
๐ก Pro Tip
Use sudo sparingly. Running everything as root is dangerous โ one typo could wipe your system. Only use sudo when you actually need elevated privileges.
chmod, chown, sudo
Practice changing permissions and ownership.
// chmod, chown, sudo โ simulated
console.log("=== chmod โ Change Permissions ===");
console.log();
console.log("Numeric mode (octal):");
console.log("$ chmod 755 script.sh โ rwxr-xr-x");
console.log("$ chmod 644 readme.md โ rw-r--r--");
console.log("$ chmod 600 id_rsa โ rw-------");
console.log();
console.log("Symbolic mode:");
console.log("$ chmod +x script.sh โ Add execute for all");
console.log("$ chmod u+x script.sh โ Add execute for owner only");
console.log("$ chmod g+
...๐ Quick Reference
| Command | Description |
|---|---|
| chmod 755 file | Set permissions (rwxr-xr-x) |
| chmod +x file | Make executable |
| chown user:grp file | Change ownership |
| sudo command | Run as root |
| whoami / id | Show user info |
| groups | Show group memberships |
๐ Course Complete!
Congratulations! You've completed the Command Line course โ from basic navigation to process management and permissions. You now have the skills to work efficiently in any terminal environment. Keep practising daily and the terminal will become your most productive tool! ๐ป
Sign up for free to track which lessons you've completed and get learning reminders.