Unit 7 路 Files, Permissions, and Scheduled Jobs 路 Lesson 20 of 25
File Permissions That Are Worth Points
A short list of files to check, and the music and video files hiding in home folders.
Which permissions actually matter?
Not all of them. Four files carry almost all of the risk, and one command shows you all four:
ls -l /etc/shadow /etc/passwd /etc/group /etc/sudoers
The thing to look for is a w in the last three letters. That means everyone on the machine can change the file, and on these four files that is serious.
Why a writable password file is the worst one
It is not that passwords leak. It is that anyone can replace a stored password with one they picked, and then log in as that account. Nothing has to be cracked.
Fixing it is two commands:
sudo chmod 640 /etc/shadow
sudo chown root:shadow /etc/shadow
The first sets who may read and write it. The second sets who owns it. You need both.
Music and video files
Most competition ReadMes say music and video files are not allowed on the machine.
Search for them like this, and read the whole list before deleting anything:
sudo find /home /root -type f \( -name "*.mp3" -o -name "*.mp4" -o -name "*.wav" -o -name "*.avi" -o -name "*.mkv" -o -name "*.mov" -o -name "*.flac" -o -name "*.m4a" -o -name "*.ogg" \) 2>/dev/null
That is a long line, so copy it rather than typing it. Three things about it are worth knowing, because each one is a way people miss a file:
馃挕 Delete every single one, or you get nothing. This is one check covering all of them, not a point per file. Leave one behind and you score exactly the same as if you had never looked. They are put in different people's folders on purpose.
Delete them
Add -delete to the end of the same command and it removes everything it found, which is safer than copying paths out by hand:
sudo find /home /root -type f \( -name "*.mp3" -o -name "*.mp4" -o -name "*.wav" -o -name "*.avi" -o -name "*.mkv" -o -name "*.mov" -o -name "*.flac" -o -name "*.m4a" -o -name "*.ogg" \) -delete 2>/dev/null
Then run the search again without -delete. When it prints nothing at all, you are done.
If it still does not score
Check the wastebasket. Deleting a file in the Files app moves it rather than removing it, and it is still on the machine:
sudo find /home /root -path "*Trash*" -type f 2>/dev/null
Empty the wastebasket, or delete those too.
Try it yourself
ls -l /etc/shadow /etc/passwd /etc/group /etc/sudoers # any w in the last three?
Then run the media search above, delete what it finds, and run it once more. It printing nothing is the only proof that you got them all.
Do this lesson for real
With a free account you get the terminal, the challenges and the checks that go with every lesson in CyberPatriot Linux: Tokyo Jujutsu High, and your progress is saved as you go. CyberAcad is a 501(c)(3) nonprofit, so there is nothing to pay.