~/.sqliterc

TL;DR: echo '.mode box' > ~/.sqliterc SQLite is a great database (although often overlooked) with a bit of annoying CLI defaults. For instance: sqlite> select * from Album limit 10; 1|For Those About To Rock We Salute You|1 2|Balls to the Wall|2 3|Restless and Wild|2 4|Let There Be Rock|1 5|Big Ones|3 6|Jagged Little Pill|4 7|Facelift|5 8|Warner 25 Anos|6 9|Plays Metallica By Four Cellos|7 10|Audioslave|8 Three columns, two of them are numbers, and yet things are hard to read. Write .mode box in your ~/.sqliterc and things change dramatically: ...

199 words

Authorize SSH keys

How often have you asked or have been asked to provide public SSH keys in order to get authorized into given server or Git repository? I’ve heard horror stories of people providing private keys, by mistake. GitHub and GitLab ease this process greatly, but are not advertising it well enough. You can append .keys to the URL of your profile in order to receive the public keys you have on your account in a format to directly pipe it into ~/.ssh/authorized_keys: ...

93 words

find tricks

Tasks I tend to forget how to perform with find(1) . Delete matched files The most trivial one: find <path> [..] -delete (e.g. find . -name foo -delete). However, depending on the OS -delete might not be available. In that case, see the next one. Execute command with matched files find <path> [..] -exec <cmd> '{}' \; is executed once for each matched file and the relative path to it is replaces '{}' and I always forget that \;, which might be omitted depending on a bunch of weird shell-isms (e.g. find . -name foo -exec rm -f '{}' \;). ...

219 words

Generate password

pwgen [length] [count] By default it generates a bunch of passwords in columns. However with args it can be ustructed to generate one fairly long secret (64 characters): pwgen 64 1 It has fairly good number of ways to configure what and how exactly to generate. The downside of this approach is that pwgen(1) is probably not installed by default on your machine. /dev/urandom Reading directly from /dev/urandom is the way to go on pretty much any UNIX these days (or fallback to /dev/random, although both are the same except on Linux) without having to install anything. The only question is how to make it output plain-text. ...

218 words

git bisect

git bisect provides easy to use binary search approach in order to find a bad commit. This tip assumes you know how it works is in general, but always forget what the commands are precisely. Prepare a single command that tries to reproduce the bug (e.g. script, test) off tree. Bisect is about to start jumping around, so it can’t be in the tree. git bisect start: begin the bisect session. git bisect bad: mark current HEAD as a bad commit (i.e. the bug is reproducible). git bisect good <commit-ref>: some known commit in the past, where the bug does not exist. You get dropped at a given commit. Try the command/test/script from step 1 and: if the bug exists: git bisect bad if the bug does NOT exist: git bisect good Repeat until the initial bad commit is found. git bisect reset. ...

206 words

nmap

Find hosts in a range nmap -sn 1.2.3.0/24 HOST DISCOVERY: -sL: List Scan - simply list targets to scan -sn: Ping Scan - disable port scan -Pn: Treat all hosts as online -- skip host discovery -PS/PA/PU/PY[portlist]: TCP SYN, TCP ACK, UDP or SCTP discovery to given ports -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes -PO[protocol list]: IP Protocol Ping -n/-R: Never do DNS resolution/Always resolve [default: sometimes] --dns-servers <serv1[,serv2],...>: Specify custom DNS servers --system-dns: Use OS's DNS resolver --traceroute: Trace hop path to each host Port Scanning Quick TCP SYN scanning (-sS: requires root), skipping host discovery (-Pn), of most popular ports: ...

259 words

rsync

rsync -arvzh [host:]/source/path/ [host:]/destination/path Note the trailing slash in source path: this avoids creating [host:]/destination/path/path. -a: archive (i.e. ensures that symlinks, attributes, permissions, owner, etc. are preserved) -r: recursive -v: verbose (second v gives what files are being skipped and some stats at the end) -z: compress -h: human-readable format of numbers --del | --delete: delete files on the destination that are not sent from the source --stats: file-transfer statistics at the end -m: prune empty directories from file-list -t: preserve modification times ...

99 words

SSH into an ancient machine

TL;DR: ssh -oHostKeyAlgorithms=+ssh-rsa -oRequiredRSASize=1024 <user>@<host> Have you ever tried to SSH into an old machine, say a managed switch, UPS or router from the previous decade only to get declined with the following error: Unable to negotiate with <host>: no matching host key type found. Their offer: ssh-rsa,ssh-dss It’s frustrating, isn’t it? OpenSSH implements all of the cryptographic algorithms needed for compatibility with standards-compliant SSH implementations, but since some of the older algorithms have been found to be weak, not all of them are enabled by default. If you want to learn more about it, definitely should read OpenSSH Legacy Options . ...

187 words

Watch for file changes

TL;DR: inotifywait -m -e close_write -e delete -e move $(pwd) Example output under different conditions: touch foo && echo ... > foo /path/to/watched/dir/ CLOSE_WRITE,CLOSE foo mv foo bar /path/to/watched/dir/ MOVED_FROM foo /path/to/watched/dir/ MOVED_TO bar rm bar /path/to/watched/dir/ DELETE bar Text editors This is where things get interesting vim /path/to/watched/dir/ CLOSE_WRITE,CLOSE foo Boring, right? However, let’s do :set backup and try again: /path/to/watched/dir/ CLOSE_WRITE,CLOSE 4913 /path/to/watched/dir/ DELETE 4913 /path/to/watched/dir/ MOVED_FROM foo /path/to/watched/dir/ CLOSE_WRITE,CLOSE foo wut? emacs /path/to/watched/dir/ CLOSE_WRITE,CLOSE foo /path/to/watched/dir/ DELETE .#foo .#foo is never created, yet deleted. ...

101 words

What is my IP?

I’m using a page setup by Jason A. Donenfeld, which he uses to illustrate setting up WireGuard : https://zx2c4.com/ip Even have it as an alias in my dotfiles : alias myip='curl -s https://zx2c4.com/ip | head -n1'

36 words