task 4.2 · chapter 4 of 8: users, permissions and sudo · 20 min
Too open, too closed
objective
Three files with the wrong permissions: a private key ssh refuses to use, a script that won’t run, and a notes file anyone can change. Read what each error says, and fix each with chmod.
answers/4.2.ymlwork/open a file in VS Code: Ctrl+P (Cmd+P on a Mac), type its name, Enter
| Lesson | Users, permissions and sudo |
|---|---|
| Set it up | make break T=4.2 |
| The key | work/keys/lab_key: ws1 accepts it for user netops |
| Your answers | answers/4.2.yml |
new to this? step by stepbeginner
make break T=4.2, thenls -l work work/keys work/bin.ssh -i work/keys/lab_key netops@ws1: read the warning. Typeyesif it asks about ws1’s key first.work/bin/hello.sh: Permission denied.- Fix each with
chmod, try again, fill in answers/4.2.yml, thenmake check T=4.2.
more in meet the lab
Permissions that are wrong both ways
Too open
Some programs refuse to work when a file is readable by people who shouldn’t read it. ssh is the strict
one: a private key, the file that proves who you are (chapter 6), must be readable by you alone. If the group
or everyone else can read it, ssh won’t use it, because anyone else on the machine could copy it.
Too closed
The opposite mistake: a script without x can’t be run as a program, however correct the code in it is. The
shell says Permission denied, which sounds like you aren’t allowed. You are; the file just isn’t marked as a
program.
Writable by everyone
A file with w for other can be changed by every user on the machine. ls -l shows it as a w in the
last set, like -rw-rw-rw-. It rarely breaks anything straight away, which is why it’s easy to miss.
in one sentence Keys must be private, programs need x, and nothing shared should be writable by everyone.
What make break leaves
$ ls -l work/keys work/bin work/team-notes.txt
-rw-rw-rw- 1 vscode vscode 64 Nov 11 05:52 work/team-notes.txt
work/bin:
total 4
-rw-r--r-- 1 vscode vscode 47 Nov 11 05:52 hello.sh
work/keys:
total 8
-rw-r--r-- 1 vscode vscode 399 Nov 11 05:52 lab_key
-rw-r--r-- 1 vscode vscode 89 Nov 11 05:52 lab_key.pub
lab_key.pub is the public half of the key pair; anyone may read that one. lab_key is the private half.
Meet the three errors
Set the task up, and look at what it made:
run in the terminalmake break T=4.2 ls -l work/keys work/bin work/team-notes.txtTry the key. If ssh first asks Are you sure you want to continue connecting?, type
yes: that’s ws1 introducing itself, and chapter 6 is all about it.run in the terminalssh -i work/keys/lab_key netops@ws1A box of
@signs, a warning in capitals, bad permissions, and then a password prompt: ssh ignored the key. Press Ctrl+C. The capitalised word that starts the warning goes inssh_warning.Try the script:
run in the terminalwork/bin/hello.sh
in one sentence ssh says a key is too open; the shell says a script without x is Permission denied.
Fix all three
Change only the permissions, not the files’ owner or contents:
work/keys/lab_key: only you can read it. Thenssh -i work/keys/lab_key netops@ws1logs in without a password.exitcomes back.work/bin/hello.sh: it runs, and only you can change it.work/team-notes.txt: everyone can read it, only you can change it.
Fill in ssh_warning and run make check T=4.2.
hint
Each of the three is one row of the table of numbers in task 4.1.
hint
ls -l after each chmod, to see that it did what you meant.
show the solution
chmod 600 work/keys/lab_key
chmod 755 work/bin/hello.sh
chmod 644 work/team-notes.txt
ssh -i work/keys/lab_key netops@ws1 hostname
work/bin/hello.sh
ssh_warning: UNPROTECTED
ssh’s warning is UNPROTECTED PRIVATE KEY FILE!, and it names the permissions it found: 0644. 400 works
for the key too (read-only, even for you), and 700 works for the script. The checker accepts anything that’s
private for the key, and runnable, but not writable by others, for the script.
5 check: run it, then prove it
$ make check T=4.2when it's right, you'll see
╭─ task 4.2 · too open, too closed
│ ✓ the word ssh shouted about the key (challenge): ...
│ ✓ work/keys/lab_key: only you can read it (challenge): it is ...
│ ✓ and ssh logs in to ws1 with it (challenge)
│ ✓ work/bin/hello.sh runs, and only you can change it (challenge): it is ...
│ ✓ work/team-notes.txt: everyone can read it, not everyone can change it (challenge): it is ...
╰─ 5/5 checks passed verified