`gpg` encrypt/decrypt with a passphrase

gpg encrypt/decrypt with a passphrase

ubuntu gpg rfc2119

Sometimes you’ve got some files that you don’t want to lose, for instance private keys (think of gpg and Google authenticator), so I store them in multiple places (to be sure that I won’t lose the file) and encrypted since I can’t keep an eye on every place I put my files.

HW setup

  1. Put your favorite security conscious live Linux distribution on a USB key.
  2. Put your keys.tar.gz.gpg on it (if you have already done this HOWTO once).
  3. Boot this key on a computer you trust. It should have no network (Ethernet/Wifi/4G/Bluetooth) connection, and ideally no local storage.

First time

  1. Boot on your trusted computer with your trusted boot media.
  2. Create a directory.
    mkdir keys
    
  3. Put your keys into it (your command line MAY differ a bit).
    echo "Happy holidays" > keys/key1.txt
    
  4. Encrypt all your keys. gpg will ask you a passphrase twice, don’t forget it!
    tar cvzf - keys | gpg --cipher-algo AES256 -c -o keys.tar.gz.gpg
    keys/
    keys/key1.txt
    
  5. Destroy the unencrypted keys:
    rm keys -rf
    
  6. Now store keys.tar.gz.gpg.

Key recovery or update

  1. Boot on your trusted computer with your trusted boot media.
  2. Recover you keys, gpg will ask for your passphrase
    gpg -d < keys.tar.gz.gpg | tar xvzf -
    keys/
    keys/key1.txt
    
  3. Use/update/… your keys
    cat keys/key1.txt
    Happy holidays
    
  4. Encrypt all your keys. gpg will ask you a passphrase twice, don’t forget it!
    tar cvzf - keys | gpg --cipher-algo AES256 -c -o keys.tar.gz.gpg
    keys/
    keys/key1.txt
    
  5. Destroy the unencrypted keys:
    rm keys -rf
    
  6. Now store keys.tar.gz.gpg.

~~~

Question, remark, bug? Don't hesitate to contact me or report a bug.