Page ↑ / Page ↓ to move · scroll works too
Linux & DevOps — Lecture 2 of 8
The mental model is in place.
Today it’s the shell and SSH —
the two tools you’ll touch in every lecture after this one.
Every later lecture assumes you’re already fluent here: writing a systemd unit, running dnf, editing a config file, deploying a container — all of it happens inside a shell, usually once you’ve reached over SSH. This lecture is the floor everything else stands on.
It reads text you type, parses it into a command plus arguments, and asks the kernel to run it. Nothing more mystical than that — it happens to be the program that starts every other program you run.
. is here, .. is the parent directory, ~ is your home directory, and - is "wherever I just was" — cd with no argument also goes home.ls -laAn absolute path starts with / and means the same thing regardless of where you’re standing; a relative path is resolved against your current directory.
Critical distinction: the shell expands wildcards and brace lists into a list of matching filenames before the command ever runs — ls never sees the wildcard itself, it sees a list of real filenames.
Double quotes still expand variables; single quotes take everything literally. A bare, unquoted variable also gets word-split and glob-expanded — the reason experienced sysadmins quote almost everything.
name="prod-web-01"exportexport PATH="$PATH:/opt/app/bin"env or printenv lists the environment a process would inherit; PATH — the list of directories searched for commands — is the one you'll edit most./etc/profile and /etc/profile.d/*.sh — system-wide, read once at login~/.bash_profile — per-user, read once at login~/.bashrc — per-user, read for every new interactive shellalias and function definitions belong in ~/.bashrc, not the login filesstdout and stderr are separate streams for a reason — a script can log errors while still piping clean data downstream.
> overwrites, >> appends. 2>&1 means "point stream 2 at wherever stream 1 currently points" — order matters, so it goes after the stdout redirect.Each command’s stdout becomes the next one’s stdin — the Unix philosophy in one keystroke: small tools, each doing one thing, composed on demand.
-i ignore case -v invert match -n show line numbers-r recurse into directories -c count matches-E extended regular expressionssed -i edits the file in place — always safe to try a command without -i first, sanity-check the output, then add it back. awk splits each line into fields ($1, $2, …) on whitespace, or on -F.That second line is a classic: sort so identical lines are adjacent, count consecutive duplicates, sort the counts descending, keep the top few — a five-second “what’s most common” report.
xargs takes lines on stdin and turns them into arguments for another command — how find's results get handed off to rm, grep, or anything else.The shebang picks the interpreter; chmod +x makes it executable. set -euo pipefail is close to a standard header: exit on error, exit on an unset variable, and fail the whole pipeline if any stage of it fails.
Every command leaves an exit code behind in $? — 0 means success, anything else means failure. Scripts are expected to honor the same convention.
if, test, and [[ ]]-f regular file -d directory -z/-n empty/non-empty string-eq -ne -gt -lt -ge -le for integers == != for strings[[ ]] over [ ] — fewer quoting surprisesEach user has their own crontab; system-wide jobs also live under /etc/cron.d/. Always log cron output somewhere — no terminal is watching when it runs.
An automation script that runs on a schedule, or gets re-triggered after a failure, will eventually run more than once against the same state. Design for that from the start:
if [[ ! -d /opt/app ]]; then mkdir /opt/app; fi instead of assuming it doesn't exist yetsystemctl enable, mkdir -p, rsyncset -e, meaningful exit codes, and logs a human can read afterwardps aux is a snapshot; top is the live, refreshing view — press q to quit, k to kill a PID from inside it.-15 (SIGTERM) asks nicely, -9 (SIGKILL) does not — reach for -9 only when -15 is ignored& backgrounds a job; nohup keeps it running after the shell exitsdf is disk space by filesystem, du is disk space by directory — the two questions "am I out of space" and "what's using it" need different commands. /proc is a live window into kernel state, readable like any other file.How you'll reach every one of these machines from now on.
sshd daemon, listening on port 22, and hands you a shell on the other end — everything from that point on is just the shell you already know, running somewhere else.That fingerprint gets written to ~/.ssh/known_hosts. If it ever changes unexpectedly on a later connection, SSH refuses outright — that’s not a bug, it’s the whole point: someone or something on the network changed.
ssh-copy-id appends your public key to the remote ~/.ssh/authorized_keys — the private key never leaves your machine, and never should.Every flag you’d otherwise type on the command line can live in a Host block — including jump-host and forwarding settings covered later in this lecture.
Turn off password auth after confirming key-based login works — locking yourself out of a remote VM is a genuinely bad afternoon. firewalld, not the SSH config, is what decides whether port 22 is reachable at all.
The same tunnel, put to work: files, commands, and traffic.
scp is a straightforward copy; rsync compares source and destination and transfers only what changed — the one to reach for on anything larger than a single small file, or anything you'll sync repeatedly.This is the shape every remote-automation script takes — a webhook listener, a deploy script, a monitoring check — a local Bash script that runs a handful of commands on a remote box, one ssh call at a time.
-L — reach a remote-only port from your laptop, e.g. an internal dashboard-R — expose something on your side to the remote host-D — a SOCKS proxy through the tunnel for anything, not just one portssh-agent unlocks your key once per session instead of per connection; -A forwards that agent through a jump host so you don't copy private keys around. ControlMaster reuses one TCP connection for every subsequent SSH to the same host — later connections are near-instant.Nothing here is new — a loop, an if-style short circuit, and ssh calls. This exact shape, scaled up, is what the capstone’s deployment pipeline is built from.