一 安装方法
[root@centos gnupg-2.1.4]# yum install gnupg
二 检测安装是否成功
[root@centos gnupg-2.1.4]# gpg --help
如果屏幕显示GPG帮助,就表示安装成功。
三 生成密钥对
-
[root@centos gnupg-2.1.4]# gpg --gen-key
-
gpg (GnuPG) 2.0.22; Copyright (C) 2013 Free Software Foundation, Inc.
-
This is free software: you are free to change and redistribute it.
-
There is NO WARRANTY, to the extent permitted by law.
-
-
gpg: directory `/root/.gnupg' created
-
gpg: new configuration file `/root/.gnupg/gpg.conf' created
-
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
-
gpg: keyring `/root/.gnupg/secring.gpg' created
-
gpg: keyring `/root/.gnupg/pubring.gpg' created
-
Please select what kind of key you want:
-
(1) RSA and RSA (default)
-
(2) DSA and Elgamal
-
(3) DSA (sign only)
-
(4) RSA (sign only)
-
Your selection? 1 #选择密钥类型(这里我们选择加密算法是RSA、数字签名算法也是RSA)
-
RSA keys may be between 1024 and 4096 bits long.
-
What keysize do you want? (2048) 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) 1y #设置密钥有效期(一年)
-
Key expires at Mon 14 Oct 2019 09:51:43 AM CST
-
Is this correct? (y/N) y #确认有效性
-
-
GnuPG needs to construct a user ID to identify your key.
-
-
Real name: cakin #输入姓名
-
Email address: 798102175@qq.com #输入邮箱地址
-
Comment: cakin #输入备注
-
You selected this USER-ID:
-
"cakin (cakin) <798102175@qq.com>"
-
-
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O #选择OK
-
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.
-
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: /root/.gnupg/trustdb.gpg: trustdb created #创建信任网的数据库
-
gpg: key F15FE9FE 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: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
-
gpg: next trustdb check due at 2019-10-14
-
pub 2048R/F15FE9FE 2018-10-14 [expires: 2019-10-14] #F15FE9F密钥生成完毕
-
Key fingerprint = 9B42 B3CC DBA4 B411 ACEA F0F5 08C9 3BF3 F15F E9FE
-
uid cakin (cakin) <798102175@qq.com>
-
sub 2048R/E672385C 2018-10-14 [expires: 2019-10-14]
四 查看刚才生成的公钥
-
[root@centos gnupg-2.1.4]# gpg --export --armor E672385C
-
-----BEGIN PGP PUBLIC KEY BLOCK-----
-
Version: GnuPG v2.0.22 (GNU/Linux)
-
-
mQENBFvCof4BCACyb/vGxaAqlpT3X/XAkXwV34j7e+KhrBEKdDIjY3Uwc7tmXfcf
-
0gtyJ+XYGjo/umz9lfD1eCfmqHqXAX4yw6qCqSonb7MforYYVwIcC9MgCY4zJS93
-
mteKLnJBBdEinylC34EAYKKJ8+nVJ0j8J4AREcFELseqpzbzszKqAcj+ZSif5ov+
-
sOSaMxKJfFLmxw/7MQ/imL0pko93VQtWdIXVlCIlw9CcWNxkDsR1rOeHlm7nEPTb
-
tjzdto+nZR85J93eAWvJuFc+sQVh6jqtVf8d7/RxbCxLxyXCZITIvCY/G8exDE5c
-
3kzhV+lHrAnQVXUeLfkR73MaLUlyjmdkgt/XABEBAAG0IGNha2luIChjYWtpbikg
-
PDc5ODEwMjE3NUBxcS5jb20+iQE/BBMBAgApBQJbwqH+AhsDBQkB4TOABwsJCAcD
-
AgEGFQgCCQoLBBYCAwECHgECF4AACgkQCMk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H7CwAJDxAE5HUX8EaMxU2
-
RAHumd1Z9Otqfds38yeHTxTGhCszu3DteYWX6f0kwuZmLfAGUT7Kv/idJBY=
-
=4oaQ
-
-----END PGP PUBLIC KEY BLOCK-----
五 列出密钥
-
#list-keys 参数列出系统已有的密钥
-
[root@centos gnupg-2.1.4]# gpg --list-keys
-
#显示公钥文件名
-
/root/.gnupg/pubring.gpg
-
#显示公钥特征(4096位,Hash字符串和生成时间)
-
pub 2048R/F15FE9FE 2018-10-14 [expires: 2019-10-14]
-
#显示用户ID
-
uid cakin (cakin) <798102175@qq.com>
-
#显示私钥特征
-
sub 2048R/E672385C 2018-10-14 [expires: 2019-10-14]
六 将公钥导入到文件
公钥文件(.gnupg/pubring.gpg)以二进制形式储存,armor 参数可以将其转换为 ASCII 码显示。
"用户 ID"指定哪个用户的公钥,output 参数指定输出文件名(public-key.txt)。
-
[root@centos gnupg-2.1.4]# gpg --armor --output public-key.txt --export cakin
-
[root@centos gnupg-2.1.4]# cat public-key.txt
-
-----BEGIN PGP PUBLIC KEY BLOCK-----
-
Version: GnuPG v2.0.22 (GNU/Linux)
-
-
mQENBFvCof4BCACyb/vGxaAqlpT3X/XAkXwV34j7e+KhrBEKdDIjY3Uwc7tmXfcf
-
0gtyJ+XYGjo/umz9lfD1eCfmqHqXAX4yw6qCqSonb7MforYYVwIcC9MgCY4zJS93
-
mteKLnJBBdEinylC34EAYKKJ8+nVJ0j8J4AREcFELseqpzbzszKqAcj+ZSif5ov+
-
sOSaMxKJfFLmxw/7MQ/imL0pko93VQtWdIXVlCIlw9CcWNxkDsR1rOeHlm7nEPTb
-
tjzdto+nZR85J93eAWvJuFc+sQVh6jqtVf8d7/RxbCxLxyXCZITIvCY/G8exDE5c
-
3kzhV+lHrAnQVXUeLfkR73MaLUlyjmdkgt/XABEBAAG0IGNha2luIChjYWtpbikg
-
PDc5ODEwMjE3NUBxcS5jb20+iQE/BBMBAgApBQJbwqH+AhsDBQkB4TOABwsJCAcD
-
AgEGFQg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kDFDfs6r7uckD2w7vi4M3YjG2XH7CwAJDxAE5HUX8EaMxU2
-
RAHumd1Z9Otqfds38yeHTxTGhCszu3DteYWX6f0kwuZmLfAGUT7Kv/idJBY=
-
=4oaQ
-
-----END PGP PUBLIC KEY BLOCK-----
七 导出私钥
export-secret-keys 参数可以转换私钥。
-
[root@centos gnupg-2.1.4]# gpg --armor --output private-key.txt --export-secret-keys
-
[root@centos gnupg-2.1.4]# cat private-key.txt
-
-----BEGIN PGP PRIVATE KEY BLOCK-----
-
Version: GnuPG v2.0.22 (GNU/Linux)
-
-
lQO+BFvCof4BCACyb/vGxaAqlpT3X/XAkXwV34j7e+KhrBEKdDIjY3Uwc7tmXfcf
-
0gtyJ+XYGjo/umz9lfD1eCfmqHqXAX4yw6qCqSonb7MforYYVwIcC9MgCY4zJS93
-
mteKLnJBBdEinylC34EAYKKJ8+nVJ0j8J4AREcFELseqpzbzszKqAcj+ZSif5ov+
-
sOSaMxKJfFLmxw/7MQ/imL0pko93VQtWdIXVlCIlw9CcWNxkDsR1rOeHlm7nEPTb
-
tjzdto+nZR85J93eAWvJuFc+sQVh6jqtVf8d7/RxbCxLxyXCZITIvCY/G8exDE5c
-
3kzhV+lHrAnQVXUeLfkR73MaLUlyjmdkgt/XABEBAAH+AwMCMhtLuW8wbVvjUU4t
-
V8m3nnbO3wvy2Ai7g3154WM54Kcz6L5EOBq3ZvBrd5fsz5o2/elS8YrR4M4evSQy
-
KsdQj/dhWvTH06r/tkse/6kOy/z/KA5PS0RPodsGpzx+fdP27TVDJuNJssrLBxYN
-
wiNLQc38VZhikntmSbStfl5GtmpohuAtsVvaF5I5yH40w2cDUJXe1qUSjRQmHLTm
-
s+xFgXG2PCf99oKGBGYr92lnDwtvcLWJqx0CSUI5ExovmA2d2ptyHUzfLnwhXeF1
-
c3CTVSa9dKilPDx6tukyb69VVtHfHKoxbfkOh+7x6PboKg++HMLnVX4cdg2DLWxb
-
GFU74VEFyVkslJY6vZ5f9d13HOw5HTzguJz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