gpg –output mygpgkey_sec.gpg –armor –export-secret-key ABCDFE01

通过How-To: Import/Export GPG key pair | Debian/Ubuntu Tips & Tricks.

 

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:

$ 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

$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.

$ 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:

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

2. Import the GPG key

Now, log in the remote host:

$ ssh user@remotehost

And then import:

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

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:

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

That’s it 🙂

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注