How to Import/Export GNU GPG Keys
How to Import/Export GPG Keys-
Step 1) List GPG Keys –
[root@test-host ~]# gpg -kv
/root/.gnupg/pubring.gpg
————————
pub 1024D/F9F17DC2 2012-09-27 Test GPG key (Created by Arun) <arun@my.com>
sub 2048g/F173E2CC 2012-09-27
pub 1024D/5A6C12B1 2013-02-25 Test2 <abagul@my.com>
sub 1024g/CA7BF220 2013-02-25
Step 2) How to Export GPG Key –
[root@test-host ~]# gpg –armor –export –output /tmp/mykey.pub -r ‘5A6C12B1’
[root@test-host ~]# cat /tmp/mykey.pub
—–BEGIN PGP PUBLIC KEY BLOCK—–
Version: GnuPG v1.2.6 (GNU/Linux)
[root@test-host ~]# gpg –armor –export-secret-key -r 5A6C12B1 –output /tmp/mykey.pri
[root@test-host ~]# cat /tmp/mykey.pri
—–BEGIN PGP PRIVATE KEY BLOCK—–
Version: GnuPG v1.2.6 (GNU/Linux)
Step 3) How to Import GPG Keys –
[arunb@test-host2 ~]$ gpg –import /tmp/mykey.pri
gpg: keyring `/saba/arunb/.gnupg/secring.gpg’ created
gpg: key 5A6C12B1: secret key imported
gpg: key 5A6C12B1: public key Test2 <abagul@my.com> imported
[arunb@test-host2 ~]$ gpg –import /tmp/mykey.pub
gpg: key 5A6C12B1: key Test2 <abagul@my.com> 2 new signatures imported
[arunb@test-host2 ~]$
Step 4) Now Test GPG Encryption/Decryption –
[arunb@test-host2 ~]$ echo “arunb” |gpg -v –no-tty –passphrase-fd 0 –output /tmp/output.csv –decrypt /tmp/mytest.csv.pgp
gpg: public key is CA7BF220
gpg: using secondary key CA7BF220 instead of primary key 5A6C12B1
gpg: using secondary key CA7BF220 instead of primary key 5A6C12B1
gpg: encrypted with 1024-bit ELG-E key, ID CA7BF220, created 2013-02-25
“Test2 <abagul@my.com>”
gpg: AES256 encrypted data
gpg: original file name=’mytest_1_1.csv’
[arunb@test-host2 ~]$
Thank you,
Arun Bagul