AI Hints
Home›Linux Tutorial›Permissions Practice
Linux · Lesson 73 of 120

Practice: Permission Problems

Fix the problems.

⏱ 2 min read▶ Video at 1:36:14🎓 Free
Watch this lesson in the Linux courseWatch on YouTube ↗Full Linux course

Here are two real problems you'll meet. A script that won't run, and a secret file that anyone can read. Try to fix each one before you watch the answer.

Practice: Permission Problems
From the video: Practice: Permission Problems
  • Two real problems
  • A script that won't run
  • A secret anyone can read

Problem one: the script

Running the backup script gives permission denied. LS dash L shows why. It's RW, R, R, with no X anywhere. The fix is CH mod U plus X. Now it runs.

Terminal
./projects/scripts/backup.sh
bash: ./projects/scripts/backup.sh: Permission denied
ls -l projects/scripts/backup.sh
-rw-r--r-- 1 sam sam 33 Jan  5 09:00 projects/scripts/backup.sh
chmod u+x projects/scripts/backup.sh
./projects/scripts/backup.sh
Backing up...

Problem two: the secret

The secret file is six four four, so every user on the computer can read the wifi password. CH mod six hundred makes it private to Sam. Now when Alex tries to read it, permission denied. Exactly what we want.

Terminal
ls -l secret.txt
-rw-r--r-- 1 sam sam 31 Jan  5 09:00 secret.txt
chmod 600 secret.txt
sudo -u alex cat /home/sam/secret.txt
cat: /home/sam/secret.txt: Permission denied

A checklist for permission denied

When you see permission denied, ask three questions. Who am I? Use ID. Who owns this file, and what are its permissions? Use LS dash L. And for a script, does it have the X? Most problems are solved by one of these.

keyvalue
Who am I?id
Who owns it?ls -l
Is x missing?chmod u+x
Too open?chmod 600

Summary

No X means a script won't run, so add it with CH mod U plus X. Too open means a secret can leak, so close it with six hundred. Next, the permissions new files get by default.

Key takeaways
  • chmod u+x
  • chmod 600
  • id and ls -l
Next up: Default Permissions — umask