Page 1 of 1

How to Import/Export GPG key pair

Posted: Mon Jun 14, 2010 10:56 pm
by Neo
This tutorial will show how you can export and import a set of GPG keys from one computer to another.
This way, you can sign/encrypt the same way one different computer.

A simple way of doing it would be to:

Code: Select all

$ scp -r ~/.gnupg user@remotehost:~/
but this would import all your keyring.

If you want to import only one set of key, you first have to get the listing of your keys and find the one you want to export:

1. Export the GPG key

Code: Select all

$gpg --list-keys
/home/user/.gnupg/pubring.gpg
--------------------------------
pub 1024D/ABCDFE01 2008-04-13
uid firstname lastname (description) 
sub 2048g/DEFABC01 2008-04-13 
In this case, I am going to import key ABCDFE01.

Code: Select all

$ gpg --output mygpgkey_pub.gpg --armor --export ABCDFE01
$ gpg --output mygpgkey_sec.gpg --armor --export-secret-key ABCDFE01 
Then copy thos files over to the remote host:

Code: Select all

$ scp mygpgkey_pub.gpg mygpgkey_sec.gpg user@remotehost:~/
2. Import the GPG key

Now, log in the remote host:

Code: Select all

$ ssh user@remotehost
And then import:

Code: Select all

user@remotehost:~$ gpg --import ~/mygpgkey_pub.gpg
user@remotehost:~$ gpg --allow-secret-key-import --import ~/mygpgkey_sec.gpg 

Code: Select all

user@remotehost:~$ gpg --list-keys
/home/user/.gnupg/pubring.gpg
--------------------------------
pub 1024D/ABCDFE01 2008-04-13
uid firstname lastname (description) 
sub 2048g/DEFABC01 2008-04-13 
and then clean up:

Code: Select all

user@remotehost:~$ rm ~/mygpgkey_sec.gpg ~/mygpgkey_pub.gpg