61

How can I export a pgp-key from one machine and import it to another? The only way I figured out (in seahorse) was to import it to the section other keys.

But I want to use one single pgp-key from diffrent machines. Is this easier to solve via terminal and gpg? I'm a little bit confused about seahorse.

landroni
  • 5,941
  • 7
  • 36
  • 58
pschmidt
  • 3,819

1 Answers1

71

In a terminal, run the following:

gpg --export-secret-key -a > secretkey.asc

And on the other system, import the secret key with:

gpg --import secretkey.asc

Alternatively, if you've got ssh access to the other system you should be able to combine these two actions into a single command:

gpg --export-secret-key -a | ssh othermachine gpg --import -

Once the keyfiles have served their purpose, securely delete them:

shred secretkey.asc && rm secretkey.asc

or

shred --remove secretkey.asc

Make sure to shred and remove the key instead of using normal deletion. Additionally, instead of moving the keyfile with mv, copy it, then shred and remove the original. These methods will prevent an attacker from recovering the key through low-level bit inspection.

  • 7
    This is the correct way to copy over the key. However, I would suggest to create subkeys and only copy those over instead. The main PC will then keep the primary key so it is possible to revoke individual subkeys in case they get compromised. See for example https://wiki.debian.org/subkeys on how to do this. (I might find some time to write this an answer here.) – gertvdijk Aug 20 '13 at 18:17
  • 4
    You also need to trust the imported key on the destination machine before you can use it: http://stackoverflow.com/a/10718194/1610035 – ajdev8 Feb 14 '14 at 22:18
  • Note: if get error message error receiving key from agent: timeout - skipped, we have to restart gpg agent service via gpgconf --kill gpg-agent, then re-export private gpg key. – HaxtraZ Jan 15 '21 at 03:18
  • error sending to agent: Inappropriate ioctl for device when doing the ssh command. Are different unix usernames on both systems supported? – Bram Jan 25 '23 at 01:08