Last week I needed to move some recurring scheduled tasks from one computer over to another computer. Some of these tasks require the use of Gnu’s PGP encryption program, GnuPG, which meant that I also needed to move public PGP keys.

While researching my options, I found a two (2) different solutions to move PGP keys from one computer to another. One moves all of the pgp data stores, while the other just moves the keys.

Move the .gnupg directory

If the target computer does not have gnupg setup yet, or you do not mind replacing the existing keys and settings, then just copying over the key rings is the quickest way to make the move. One just needs to copy over the entire ~/.gnupg directory, which contains all of your keys and key rings.

First, make a copy of the .gnupg directory into an archive using the tar utility.

$ tar -cvzf gnupg_backup_yyyymmdd.tgz ~/.gnupg

Next, copy the tar archive [gnupg_backup_yyyymmdd.tgz] from the source computer to the the target computer. One can extract the tar with the command, $ tar -xzvf <filename.tgz>.

Export/Import Public and Private Keys

Another way to move your php keys from one machine to another is to export the keys on the source machine, and then import the keys on the target computer. To export all of your public php keys and save them to a file, run the command, $ gpg —export > public_keys.pgp.

To export your private php keys, run the command with the —export-secret-keys option.

To import on the target computer, run the following command.

$ gpg —import < public_keys.pgp

$ gpg —import < private_keys.pgp

–Chris