I've been working with GPG a lot lately and the need arose to export keys from one machine and import them on another machine. I couldn't find any good, well written articles for this so I decided to write one myself. I'll show you how to export first and then import the key on another machine.
Exporting
To export a key you'll need two keys, the public and secret key. To begin export the public key:
If I wanted to export the key "Jordan" to a file named myPublicKey I would execute this command:Code:# gpg --output <filename> --export <keyname>
After running this command you should be brought back to the prompt but a new file will exist named myPublicKey. Now we need to export the secret key:Code:gpg --output myPublicKey --export Jordan
If you wanted to export to mySecretKey from the user Jordan you would execute this command:Code:gpg --output <filename> --export-secret-keys <keyname>
Now that you have both keys exported we need to import the keys on a different system.Code:gpg --output mySecretKey --export-secret-keys Jordan
Importing
After you have moved the keys to a new system importing is fairly easy. Let's start by importing the public key. You issue the command
In our case we want to import myPublicKey so the command would be:Code:gpg --import <filename>
If this is your first import you will see output with WARNINGs:Code:gpg --import myPublicKey
If this isn't the first time you've ran GPG (generated a key or imported a key) you will see output similar to this:Code:gpg: directory `/jordan/.gnupg' created gpg: new configuration file `/jordan/.gnupg/gpg.conf' created gpg: WARNING: options in `/jordan/.gnupg/gpg.conf' are not yet active during this run gpg: keyring `/jordan/.gnupg/secring.gpg' created gpg: keyring `/jordan/.gnupg/pubring.gpg' created gpg: /jordan/.gnupg/trustdb.gpg: trustdb created gpg: key EC6271C0: public key "Jordan (Jordan) <my@email.com>" imported gpg: Total number processed: 1 gpg: imported: 1
Now we need to import our secret key. You import it using the same command above:Code:gpg: key EC6271C0: "Jordan (Jordan) <my@email.com>" not changed gpg: Total number processed: 1 gpg: unchanged: 1
We will import our secret key by executing:Code:gpg --import <filename>
You should see output similar to:Code:gpg --import mySecretKey
TestingCode:gpg: key EC6271C0: secret key imported gpg: key EC6271C0: "Jordan (Jordan) <no@email.com>" not changed gpg: Total number processed: 1 gpg: unchanged: 1 gpg: secret keys read: 1 gpg: secret keys imported: 1
You can test by encrypting a file on System A and moving it to System B. Use GPG to decrypt that file on System B. You should be asked to enter your passphrase and your file should look the same as on System A.
If you have any questions don't hesitate to ask!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks