Linux Basics Lesson 20 of 38
755 and still Permission denied
8 minutes
Learning goals
- Check the mode of a file before you suspect anything else.
- Find out whether a mount option such as noexec is in the way.
- Run a script without weakening the protection of /tmp, and keep its result private.
The file's mode is only half the truth, and the file system has a say as well. To find out how something is mounted, use findmnt or mount. grep is not loaded on this page, so mount | grep /tmp gives you command not found here. findmnt /tmp asks about exactly that one place, and plain mount shows the whole table. On a real server, sudo could change the mount, but it is not loaded here either, and it would be the wrong answer anyway.
Steps
Step 1/4: Start with the obvious. Show mode and owner of /tmp/backup.sh. Step 2/4: If the file is fine, look at the place. Find out with which options /tmp is mounted. Step 3/4: The backup still has to run, without weakening /tmp. Get it to work. The empty folder ~/bin is there for scripts. Step 4/4: The backup holds your private notes. Make ~/backup a folder only you can use. Scenario solved
The backup script lies in /tmp, it has 755, it belongs to you, and still: bash: /tmp/backup.sh: Permission denied. Another chmod +x changes nothing. Time to look somewhere other than the file.
-
Step 1 done solved before
Start with the obvious. Show mode and owner of /tmp/backup.sh.
Hint 1: Which option of ls shows the mode?Hint 2: Type ls -l /tmp/backup.shSolution
ls -l /tmp/backup.shWhy: 755, and it belongs to you. So the mode is not the problem, and another chmod +x cannot help. Good to know before you try more of the same.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
-
Step 2 done solved before
If the file is fine, look at the place. Find out with which options /tmp is mounted.
Hint 1: The command that shows mount points takes a path. grep is not loaded here.Hint 2: Type findmnt /tmpSolution
findmnt /tmpWhy: There it is. noexec forbids starting programs on this whole file system, whatever chmod says. On hardened servers that is the standard for /tmp.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
-
Step 3 done solved before
The backup still has to run, without weakening /tmp. Get it to work. The empty folder ~/bin is there for scripts.
Hint 1: noexec applies to /tmp. Where in your home does a script belong?Hint 2: Type cp /tmp/backup.sh ~/bin/ and then ~/bin/backup.shSolution
cp /tmp/backup.sh ~/bin/ ~/bin/backup.shWhy: bash /tmp/backup.sh also works, because bash only reads the file and nothing is started from /tmp. Copying to ~/bin is still the clean way, because the script then lives somewhere it survives a reboot, and it keeps working the way its name suggests. Remounting /tmp would take the protection away for everyone.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
-
Step 4 done solved before
The backup holds your private notes. Make ~/backup a folder only you can use.
Hint 1: Owner everything, the others nothing. As digits?Hint 2: Type chmod 700 ~/backupSolution
chmod 700 ~/backupWhy: Without x on the folder, nobody else gets to the files inside, whatever modes they have. Check with ls -ld ~/backup, which now shows drwx------.
See the solution? You get fewer XP for this scenario.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
Scenario solved
Why each step mattered
- Step 1: 755, and it belongs to you. So the mode is not the problem, and another chmod +x cannot help. Good to know before you try more of the same.
- Step 2: There it is. noexec forbids starting programs on this whole file system, whatever chmod says. On hardened servers that is the standard for /tmp.
- Step 3: bash /tmp/backup.sh also works, because bash only reads the file and nothing is started from /tmp. Copying to ~/bin is still the clean way, because the script then lives somewhere it survives a reboot, and it keeps working the way its name suggests. Remounting /tmp would take the protection away for everyone.
- Step 4: Without x on the folder, nobody else gets to the files inside, whatever modes they have. Check with ls -ld ~/backup, which now shows drwx------.
Start over? The whole scenario goes back to step 1. Your hints stay, XP only comes once.
Loading terminal …
Esc, then Tab leaves the terminal
Step 1 of 4
Cards
-
Card 1 of 2
Tap the card or press Space to turn it over.
-
Card 2 of 2
Tap the card or press Space to turn it over.
Cheat sheet
The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.
- Download PDF (PDF, 18 KB)
- View as image (PNG, 52 KB)