Skip to content

Instantly share code, notes, and snippets.

@dwightgunning
Created October 5, 2020 07:03
Show Gist options
  • Save dwightgunning/5a8b383262ec25c34f480873a842c5ac to your computer and use it in GitHub Desktop.
Save dwightgunning/5a8b383262ec25c34f480873a842c5ac to your computer and use it in GitHub Desktop.
My notes from the Linux Upskill Challenge (Sept 2020)

Linux Upskill Challenge - Notes

Day 1 - Accessing your server

Prohibit password login for the 'root' account: PermitRootLogin prohibit-password

Day 2 - Basic navigation

Use man and search with less/vim command syntax

Day 3 - Power trip!

  • less /var/log/auth.log: View the auth log with logins and sudo usage
  • timedatectl: Show clock / timezone info

Day 4 - Installing software, exploring the file structure

Midnight Commander is helpful when needing to visualise a file system and directory structures.

Day 5 - More or less...

Less commands

h - list less commands

/ - text search

n - next match
N - previous match

g - start of file G - end of file

space - next page shift + space - previous page

down key - next line up key - previous line

F - enable '-f' like behavior; ctrl-c to break

-S chop long lines

& /pattern/ - show lines containing /pattern/ (like grep)

history

!<command #> - runs the command at the given line item

Day 6 - Editing with "vim"

  • h|j|k|l: left/down/up/right navigation
  • e: end of word
  • b: begin of word
  • 0: beginning of the line
  • $: end of the line
  • a|A: Append
  • r: Replace

Fundamental command concepts: "operators" and "motions".

vimtutor is your friend.

Day 7 - Installing Apache

Dive into systemctl as it's the predominant "init system" and "system manager".

  • systemctl status cron.service
  • systemctl list-units

Day 8 - the infamous "grep"...

Plain text files are a key part of "the Unix way".

Tools for log analysis: grep, cat, more, less, cut, awk and tail

Piping cat to grep is apparently somewhat wasteful/unnecessary.

Day 9 - Ports, open and closed

  • ss -ltp: Listening ports and processes (try with sudo to show processes running as root)
  • nmap localhost: Run a port scan against the local server
  • sudo iptables -L: List iptables rules

Day 10 - Getting the computer to do your work for you

System-wide and user-specific crontab schedules exist.

System-wide cron schedule is at /etc/crontab. On Ubuntu, this is a simply schedule for launching "anacron", which in turn executes the scripts found under the /etc/cron.(daily|hourly|monthly|weekly) directories. Also of note is that anacron has additional logic to support systems that aren't online 24/7, and still ensures the jobs are executed at the specified interval.

  • cat /etc/crontab: Show the system crontab
  • crontab -l: List crontab for a user

Systemd timers are an alternative.

  • systemctl list-timers

Day 11 - Finding things

Four tools:

  • locate: Locates a file ... index is usually rebuilt nightly. Use sudo updatedb to refresh the index.
    • locate auth.log
  • find: searches down through a directory structure looking for files which match some criteria
    • find /var -name auth.log
    • find /var -mtime +3 (24 * n hours)
    • find ~ -size +100k (note + or - for gt/lt)
    • find /home/dwight -user root -exec chown dwight:dwight {} ; (executes a command against all matching files)
    • find -user dwight
    • find -group dwight
    • -o ... or condition
    • -not ... invert condition
  • grep: print lines that match patterns
    • grep dwight /var/log/auth.log
    • grep -R -i "PermitRootLogin" /etc/* (searchs the entire /etc/* directory)
    • sudo zgrep root /var/log/auth.log.4.gz (apply gunzip for compressed text files)
  • which: locate a command and print its path

Day 12 - Tranfering files

SFTP is preferred as it's based on the SSH protocol. That's likely already setup and is secure.

Day 13 - Who has permission?

Day 14 - Your little helper...

sudo -l: Show commands that a user can run with sudo... sudo -l -U <otheruser> Check another user

Day 15 - Deeper into repositories...

Listing source repostitories ... no specific command ...

  • cat /etc/apt/sources.list /etc/apt/sources.list.d/* | grep 'deb '

Searching ...

  • apt search wireguard | less
  • apt-cache dump | grep "wireguard"

Consider user PPAs.

Day 16 - 'tar' and friends...

tar cvf and tar -cvf are identical ... there's some history around the switch statements

Day 17 - From the source

make install usually needs sudo because it'll drop the installed binaries in a shared / root-restricted directory.

In general '/bin' is for key parts of the operating system, '/usr/bin' for less critical utilities and '/usr/local/bin' for software you've chosed to manually install yourself.

Day 18 - Log rotation

The 'dailycompress' option is interesting. Technically it's important because some programs cannot be instructed to close/re-open the new log file that's been rotated in. Then there's the usability nice-to-have of being able to access the previous log file witout needing to de-compress it.

Day 19 - Inodes, symlinks and stat

inodes are the indexes gather metadata about the underlying file data.

Hard links share the same inode as the linked file ... which explains most of the other differences to symlinks

Day 20 - Scripting

Convention: scripts intended to be executed by all users can be made executable (chmod +x) and copied into '/usr/local/bin'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment