天天看點

GPG 公私鑰生成

備注

gpg (GnuPG) 1.4.5
如果是2.0以上版本,需要gpg2指令      

1.GPG公鑰生成

[weblogic@10_56_81_179 ~]$ gpg --gen-key
gpg (GnuPG) 1.4.5; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.

Please select what kind of key you want:
   (1) DSA and Elgamal (default)
   (2) DSA (sign only)
   (5) RSA (sign only)
Your selection? 1
DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 
Requested keysize is 2048 bits
Please specify how long the key should be valid.
         0 = key does not expire
      <n>  = key expires in n days
      <n>w = key expires in n weeks
      <n>m = key expires in n months
      <n>y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) y

You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
    "Heinrich Heine (Der Dichter) <[email protected]>"

Real name: weblogic
Email address: [email protected]
Comment: weblogic
You selected this USER-ID:
    "weblogic (weblogic) <[email protected]>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o
You need a Passphrase to protect your secret key.

We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
++++++++++++++++++++.+++++++++++++++++++++++++.+++++++++++++++.+++++++++++++++.+++++.+++++++++++++++...+++++++++++++++++++++++++++++++++++>+++++.+++++...........>+++++.<.+++++..................................+++++

Not enough random bytes available.  Please do some other work to give
the OS a chance to collect more entropy! (Need 280 more bytes)
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
++++++++++++++++++++++++++++++++++++++++.+++++..++++++++++..++++++++++.+++++.+++++++++++++++..++++++++++..++++++++++.+++++...+++++..+++++.+++++++++++++++++++++++++>++++++++++>.+++++..............................>+++++.+++++^^^
gpg: key 3471734D marked as ultimately trusted
public and secret key created and signed.

gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0  valid:   2  signed:   0  trust: 0-, 0q, 0n, 0m, 0f, 2u
pub   1024D/3471734D 2018-09-05
      Key fingerprint = E416 0527 54A4 3523 50B2  6493 1D89 D308 3471 734D
uid                  weblogic (weblogic) <[email protected]>
sub   2048g/AB449374 2018-09-05      

2.公鑰檢視

[weblogic@10_56_81_179 ~]$ gpg --list-key
/home/weblogic/.gnupg/pubring.gpg
---------------------------------
pub   2048R/BA7E8B9D 2018-09-05
uid                  weblogic (weblogic) <[email protected]>

pub   1024D/3471734D 2018-09-05
uid                  weblogic (weblogic) <[email protected]>
sub   2048g/AB449374 2018-09-05      

3.私鑰檢視

[weblogic@10_56_81_179 ~]$ gpg --list-secret-keys
/home/weblogic/.gnupg/secring.gpg
---------------------------------
sec   2048R/BA7E8B9D 2018-09-05
uid                  weblogic (weblogic) <[email protected]>

sec   1024D/3471734D 2018-09-05
uid                  weblogic (weblogic) <[email protected]>
ssb   2048g/AB449374 2018-09-05      

4.公鑰導出

4.1.指令格式

gpg -a --export 公私鑰生成的使用者 > 導出的公鑰檔案路徑和檔案名      

4.2.指令樣式

[weblogic@10_56_81_179 weblogic]$ gpg -a --export weblogic >weblogic_pub.asc
在目前的路徑下面會生成一個weblogic_pub.asc的公鑰檔案      

4.3.備注

将上面的這個公鑰檔案weblogic_pub.asc給到需要加密的伺服器一方即可      

5.私鑰導出

5.1.指令格式

gpg -a --export-secret-keys 公私鑰生成的使用者 >導出的私鑰檔案路徑和檔案名      

5.2.指令樣式

[weblogic@10_56_81_179 weblogic]$ gpg -a --export-secret-keys weblogic >weblogic_pri.asc
目前路徑下面會生成一個私鑰的檔案weblogic_pri.asc