norboten · cheat sheet

Nine letters and a refusal — cheat sheet

linux-basics, users-permissions
# reading permissions
ls -l FILE                   # type + owner/group/others triads, owner, group
ls -ld DIR                   # the directory itself, not its contents
stat -c '%A %a %U:%G' FILE   # symbolic mode, octal mode, owner:group
id                           # who you are, and your groups

# the rule: owner triad if you own it; else group triad if you are in the group; else others.
# first match wins — the kernel never combines triads. Root bypasses read/write checks.

# changing permissions
chmod o+r FILE               # add read for others (u g o a;  + - =;  r w x)
chmod go-w FILE              # remove write for group and others
chmod 644 FILE               # rw-r--r--   (r=4 w=2 x=1, one digit per triad; replaces all nine bits)
chmod 600 FILE               # rw-------
chmod 755 DIR                # rwxr-xr-x   (x on a directory = may pass through it)
sudo -u nobody cat FILE      # test as someone who is not you

# sudo and redirection
sudo cmd > file              # cmd runs as root; > is opened by YOUR shell, as you
echo x | sudo tee file       # write a file as root
sudo sh -c 'echo x > file'   # …or put the redirection inside root's shell

# getting exactly the right text
tail -1 FILE                                  # the last line
sed -n 's/^The secret word is: //p' FILE      # just the part after the prefix
awk -F': ' '/secret word/ {print $2}' FILE
cat -A FILE                                   # $ = end of line, ^I = tab, ^M = CR

# Norboten, on a lab's screen
c                            # grade, reboot, grade again
h                            # the next hint for the selected check
r                            # back to the broken state