Practice: Permission Problems
Fix the problems.
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.

- 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.
./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.
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.
| key | value |
|---|---|
| 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