Ubuntu – The safest way to backup GPG and SSH keys

backupencryptiongnupgkeyringsssh

I have, in Ubuntu 14.10, generated a public and private GPG and SSH key set, but I am now needing to do a fresh install and don't want to lose them but don't just want to put them as text files on a USB.

So what's the safest way of backing them up?

Is there anyway in which I can encrypt the exported files of them or anything like that?

Best Answer

Your GPG secret keyring is already encrypted, though it's only as strong as your passphrase (which is true of any encryption).

I'd make a tar file of all the files you want to backup (a few folders/files listed to tar, or with -T, --files-from get names to extract or create from FILE) and pipe tar's output to GPG. Basically:

tar -c folder | gpg --output archive.tar.gpg -e

But be careful that you don't encrypt your only copy of your secret key with your secret key... i.e. don't lock the key to your safe inside your safe. Conventional (passphrase-only) encryption works too:

tar -cz --files-from=addthese.txt | gpg --cipher-algo AES256 -z 0 --output archive.tar.gz.gpg -c 

This avoids making any extra unencrypted copies of the data, that you'd have to find & wipe (or wipe all free space) if that's a concern. Any programs that use standard output can be piped into gpg too, in case it's not just plain files you're backing up.

Related Question