Skip to content

Instantly share code, notes, and snippets.

View JPvRiel's full-sized avatar

Jean-Pierre van Riel JPvRiel

  • South Africa, Johannesburg
View GitHub Profile
JPvRiel /
Last active October 10, 2022 17:27
Decode syslog priority

Decode syslog priority

Well-formed syslog message headers start with the facility and severity encoded as the priority in angle brackets, e.g. <179>.... As per RFC5424:

The Priority value is calculated by first multiplying the Facility number by 8 and then adding the numerical value of the Severity.

The python files in this gist are a demo to help showcase how to decode the priority. E.g.:

pri = 179
JPvRiel / Convert old weakly encrypted SSH private keys to the newer PKCS8
Last active November 24, 2022 14:05
Convert Old Weakly Encrypted SSH Private Keys to the Newer PKCS8 Format

Convert Old Weakly Encrypted SSH Private Keys to the Newer PKCS8 Format

The default password-based encryption for openSSH RSA private keys (generated with ssh-keygen -t rsa) has inadequate protection against brute forcing due to a weak Password-Based Key Derivation Function (PBKDF) because it used OpenSSL's key derivation with just one round of MD5.

TL;DR: Rather generate new keys with ssh-keygen -t ed25519 which by default should use the more secure PBKDF with the PKCS8 format. RSA key generation defaults to the weak PBKDF stored in the PEM format.

However, if you still need RSA to work with older Unix systems, network devices, and other systems' SSH servers are not yet upgraded with Ed25519 support, this provides info to avoid the less secure default of saving private keys in the legacy PEM format when generating RSA keys. Backward compatibility is not that much of a concern since only the SSH client needs a reasonably modern version of SSH.

Identify if the old PEM format is in use

JPvRiel / SysRq magic
Created January 9, 2019 02:26
SysRq magic keys

sysrq magic keys

This is useful for trying to recover from an unresponsive system. However, by default, Ubuntu disables the key to gain raw keyboard access.\

Sometimes part of the issue is that X/Wayland display servers have crashed due to bad graphics drivers and keyboard input isn't processed anymore, whereby changing to another console, e.g. ctrl + alt + F1 doesn't work. Since the default disables keyboard control, alt + sysrq + r, can't help salvage the situation. Hence the suggestion to at least enable system request raw keyboard control when trying to recover a system.

Ubuntu doesn't enable control of keyboard by default

Ubuntu 16.04 LTS default value:

JPvRiel /
Last active January 7, 2019 09:28
Linux MD software raid inspection

A bash script that collects some useful commands to check Linux MD software arrays and component devices for some issues, e.g.

  • RAID component device has a SMART warnings or errors.
  • A RAID with HDD and SSD mixed doesn't have the HDD components set to write-mostly or the SSD is set to write-mostly.

It can also display info. Set env var SHOW_INFO='y' or anything else, e.g. 'n' (default) to just report issues.


JPvRiel /
Created September 4, 2018 18:00
`ps` command examples

Show top 10 processes by resident memory set size

ps -eo pid,user,rsz,vsz,comm,args --sort -rss --cols 160 | head -n11
JPvRiel / spice-guest-tools Windows 10
Last active September 4, 2018 17:59
Fixing "page fault in nonpaged area" Windows 10 BSOD caused by installing spice-guest-tools


Boot failure was caused by installing spice-guest-tools which, if you read details about it, also includes the QXL driver and the install broke my Windows 10 build 17134 guest somehow. This occured on Ubuntu 16.04 LTS with QEMU emulator version 2.5.0.


BSOD with "page fault in nonpaged area" occurs after installing spice-guest-tools-latest.exe. It possibly clobbers other stable/good versions of drivers.

Automatic boot repair fails. After going through advanced options and getting to a command prompt, inspect the boot repair logs:

JPvRiel /
Last active June 22, 2019 08:00
git workflow


Merge master into branch

A good idea if upstream has had commits and, to catch up, you need to test your feature branch with changes from upstream included

git checkout feature
git pull origin master
JPvRiel /
Created November 12, 2017 19:56
Decrypt a directory of PDFs using bash, basename and qpdf

Given a working directory and a folder c with encrypted PDFs, use qpdf, basename and a bash loop:

for f in c/*.pdf; do qpdf --password=<password> --decrypt $f "$(basename -s .pdf $f).pdf"; done
JPvRiel / Find out which process has created an X
Created March 24, 2017 09:22
Find out which process has created an X window


W window has a _NET_WM_PID property set by the applicaiton. To really validate if the application has set this correctly is more work (see reference).

Simple Example

Run command and click the window

$ xprop _NET_WM_PID
JPvRiel /
Last active May 27, 2024 11:19
Enable persistent storage for the systemd journal log

Enable persistent storage for the systemd journal log


The assumed default setting in /etc/systemd/journald.conf is Storage=auto which implies that systemd journaling will only persist the journal if the expected storage location is available. Otherwise, the journal data is stored in memory and lost between reboots. On Ubuntu 16.04, /var/log/journal does not exist by default. Create it to keep and query events from previous boots.


  • Syslog still provides the persistant log records for Ubuntu 16.04, so enabling persistant systemd journal logging does cause a level of duplicaiton.
  • There are sane defaults: