Since GnuPG keyrings are important and vital to identify you in the virtual world, we need to protect it with our deal life. That also includes backing the keyrings up safely. In this section, we look into various ways of backing the primary key.
The most common and recommended way to backup the data is to create an encrypted USB storage using cryptsetup software which is widely available in any Linux Operating System today. The idea is to ensure the USB storage partition is encrypted while offline if anyone picks up the USB and tries to use it, he/she will not be able to access it.
Here's a simple gist recommended by saminiir.com to create one (The codes are for references and comprehensions, not for copy-paste usage):
# Create an encrypted USB
# -----------------------
$ lsblk
$ mount /dev/sdb /mnt/usb
$ dd if=/dev/urandom of=/mnt/usb/disk.img bs=1M count=16
$ loopdev="$(losetup -f)"
$ losetup "$loopdev" /mnt/usb/disk.img
$ cryptsetup -v luksFormat "$loopdev"
$ cryptsetup isLuks "$loopdev" && echo "Success"
$ cryptsetup open "$loopdev" usbkey
$ mkfs.ext3 /dev/mapper/usbkey
# Mount the USB. You'll be prompted to unlock the device.
# -------------------------------------------------------
$ mount /dev/mapper/usbkey /media/encrypted
# Move the secret key into the USB device
# ---------------------------------------
$ mv masterkey.asc /media/encrypted/.
# Umount the USB for safe-keeping
# -------------------------------
$ umount /media/encrypted
$ cryptsetup remove usbkey
$ losetup -d $loopdev
$ umount /mnt/usb
# Delete the local copy
# ---------------------
$ rm masterkey.asc
CryptSetup uses LUKS encryption to protect the USB device just in case anyone has the device.
The good news is that:
The bad news is that:
You can also choose some certified and recognized cloud software like your password managers. They can also store the key securely and remotely.
If you choose to backup to LastPass, be sure to use the "Secure Note" instead of the conventional password storage for sites. As of current date (September 2018), LastPass has A LOT of issues with text processing with its existing templates. Therefore, you should create your own GPG template with the following fields:
Name
- for keeping the master key full nameEmail
- for keeping the master key corresponding emailPassword
- for keeping the master key passphraseNote
- for keeping the key dataWARNING - DO NOT use text or password field to store your key data. LastPass has not been working on fixing the "new line" auto trimming bug for these fields. If you do that, your key will get corrupted as all the newline in the text gets trimmed.
Once you're done, place the data into it and save it into your LastPass account. Here's an example:
The good news are:
The bad news are:
Here are some food for thoughts for backing up your files.
There are other methods to backup your secret keys available across the internet. However, I personally tested and find this 2 methods are sufficient enough to fulfill the backup rule. The rule states that at any time, the data must:
3
- Always have 3 copies (local offline storage, remote cloud storage, local machine)2
- Store 2 copies in 2 different mediums (local offline storage, remote cloud storage/local machine)1
- Keep one copy offsite (remote cloud storage) That's all about choosing backup medium for backing up GPG key.