1

I've used gpg2 to generate some keys on my Ubuntu 16.04 server. Now I have to move the machine. I need to transfer all generated keys to a Mac. I think I just have to copy the ~/.gnupg files.

But where do I have to store it to get them called via gpg --list-secret-keys --keyid-format LONG [email protected]? Same place?

And how do I install gpg2 on my Mac? homebrew gpg2 is not existing.

2 Answers 2

5

On the machine that initially has the keys (the Ubuntu machine):

Export the public keys:

gpg --export --armor --output=key_public.asc

Export the private keys:

gpg --export-secret-keys --armor --output=key_secret.asc

Copy the exported files to the second machine (the Mac).

Import the keys:

gpg --import --armor key_public.asc

and

gpg --import --armor key_secret.asc

The above commands will export all the keys in your keyring. If you just want a specific key/s, you need to specify it/them by uid.

3
  • This only copies keys and signatures, but omits trust (if you set up any). You might especially have to issue ultimate trust to your own secret key.
    – Jens Erat
    Oct 21, 2017 at 11:40
  • I did exact this, but I just get the public key imported. I thought using --export will export both keys... Oct 21, 2017 at 23:18
  • My memory failed me. Upon testing, --export only exports public keys. I've updated the answer with corrected info.
    – chraffx
    Oct 22, 2017 at 1:49
2

Just put them again to ~/.gnupg, but make sure to fix any user ID issues afterwards: chown -R $USER:$USER ~/.gnupg. If you still have issues afterwards, make sure you run GnuPG under the expected user and thus the GnuPG is searching in the right GnuPG home directory. gpg --version will also print the home directory in use.

The gnupg homebrew package installs GnuPG 2.2 at the time writing this post. What you used to execute as gpg2 is now gpg, also Ubuntu and other Linux distributions switched to releases of GnuPG 2.x as default for gpg by now. Some time ago, there was a dedicated gnupg2 package in homebrew, but this is now merged into gnupg.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .