Encrypted offsite backup using GPG with private key never on backup server

backupgpg

I have a backup server, that creates xz compressed tar archives of directory trees to be backed up. These tar archives can get huge (multiple TBs), are split into pieces (2.5TB), and each piece is written to a LTO-6 tape, and the tapes go offsite.

Now I want to add encryption. I can GPG encrypt the tar archive before splitting, using public-private key encryption, and with one or more recipients (admin public keys).

However, in case of recovery, at least one admin needs to put his private key onto the backup server, since the files are too huge to be unpacked anywhere else.

GPG uses a hybrid encryption scheme under the hood, with a symmetric cipher like AES with a session key, and only that session key gets public-private key encrypted for the recipients.

Is there a way to let an admin provide the session key for decrypting file to be recovered without putting the private key onto the backup server?


I could reinvent the wheel of course:

  • create a random session key on the backup server per each file to be backed up
  • use GPG symmetric encryption to encrypt the file
  • use GPG asymmetric encryption to encrypt the session key for each recipient

But is there a "standard" or builtin or best-practice way of achieving above?

Best Answer

This is definitely possible with the --show-session-key and --override-session-key options.

First you need the beginning of your encrypted file. This is where the encrypted session key is stored.

root@qwerty:~/gpg# head -c 1024k bigfile.gpg > head.gpg

Then copy it to your workstation and retrieve the session key

PS C:\Users\redacted\Downloads> gpg --show-session-key .\head.gpg
gpg: encrypted with 2048-bit RSA key, ID DC21D645, created 2016-02-01
  "admin <admin@domain.tld>"
gpg: session key: '9:926EC16DF1248A1C4401F5AD5D86C63C1BD4BF351ECEFB121C57EC209DE3933D'

Now you can decrypt the file using your session key

root@qwerty:~/gpg# gpg -d -o bigfile --override-session-key 9:926EC16DF1248A1C4401F5AD5D86C63C1BD4BF351ECEFB121C57EC209DE3933D bigfile.gpg
gpg: encrypted with 2048-bit RSA key, ID DC21D645, created 2016-02-01
  "admin <admin@domain.tld>"
Related Topic