Quick reference
1. Don't
rm -rf $APP_DIR/If APP_DIR is empty, this becomes rm -rf /.
Do instead
rm -rf "${APP_DIR:?}"/${VAR:?} stops the command if the variable is empty.
2. Don't
crontab -rOne key away from -e. Deletes the whole crontab, no question.
Do instead
crontab -l > ~/crontab.bakBack it up first, then edit with crontab -e.
3. Don't
echo '10.0.0.5 db' > /etc/hosts\> replaces the whole file. localhost is gone too.
Do instead
echo '10.0.0.5 db' >> /etc/hosts\>> appends. Better still, copy the file first.
4. Don't
systemctl restart sshdOne typo in sshd_config and nobody can log in again.
Do instead
sshd -t && systemctl reload sshdTest the config first. Keep a second session open.
5. Don't
rebootIn the wrong terminal tab, that is production.
Do instead
apt install molly-guardAsks for the host name before a reboot over SSH.
Explained
rm -rf $APP_DIR/If APP_DIR is empty or unset, the shell runsrm -rf /. Instead:rm -rf "${APP_DIR:?}"/— the :? makes the shell stop with an error if the variable is empty.
crontab -rr and e sit right next to each other on the keyboard. -e edits. -r deletes the whole crontab without asking. Instead:crontab -l > ~/crontab.bakbefore you touch it, and keep that habit.
echo '10.0.0.5 db' > /etc/hostsA single > replaces the entire file. Your localhost line is gone, and strange things start to break. Instead: >> appends. And for any system file, cp it to a .bak first.
systemctl restart sshdAfter editing sshd_config, one typo means the SSH daemon does not come back, and on a remote server that can mean no way in. Instead:sshd -tto test the config, then reload, with a second session still open.
rebootTyped into the wrong terminal tab, that is a production outage. Instead: install molly-guard on Debian or Ubuntu. Over SSH, it asks you to type the host name before arebootor shutdown goes through.
The pattern behind all five: the dangerous version is the fast one. The safe version adds one check that takes a second.
Before anything risky, three commands: hostname, whoami, pwd. Where am I, who am I, and where exactly will this run?
In one line
Slow down for one second. Most outages start with a command that ran too fast.
Before anything risky
hostname; whoami; pwdMore notes: Linux
Open in the notes app: search, filters, copy This note on GitHub