1.可以使用 gpg --help 查看说明

2.使用gpg --gen-key 生成key

:~$ gpg --gen-key
gpg (GnuPG) 1.4.20; Copyright (C) 2015 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.

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 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) ==> key 到期时间,默认是永不到期
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) <heinrichh@duesseldorf.de>"

Real name: ==> 输入名字
Email address: ==> 输入邮箱
Comment: ==> 输入描述
You selected this USER-ID:
"tomato (I am tomato) <tomato@tomato.com>"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? ==>输入 O,代表输入无误
You need a Passphrase to protect your secret key.

gpg: gpg-agent is not available in this session
Enter passphrase: ==>输入密码
Repeat passphrase: ==>再次输入密码

gpg: gpg-agent is not available in this session
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 118 more bytes) ==>gpg需要随机数, 做自己的事情就好,等它自己收集完后,会自动关闭.

====>大概15分钟

.....+++++
gpg: /home/yangxiaoyu/.gnupg/trustdb.gpg: trustdb created
gpg: key 48C72730 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
pub 2048R/48C72730 2018-09-26
Key fingerprint = 44BA F73B 2629 519B 00E8 2C4D 0EED 90BA 48C7 2730
uid tomato (I am tomato) <tomato@tomato.com>
sub 2048R/1EE2CCE3 2018-09-26
====> 生成KEY

3.
使用 gpg -k 显示公钥
:~$ gpg -k
/home/yangxiaoyu/.gnupg/pubring.gpg
-----------------------------------
pub 2048R/48C72730 2018-09-26
uid tomato (I am tomato) <tomato@tomato.com>
sub 2048R/1EE2CCE3 2018-09-26

使用 gog -K 显示私钥
:~$ gpg -K
/home/yangxiaoyu/.gnupg/secring.gpg
-----------------------------------
sec 2048R/48C72730 2018-09-26
uid tomato (I am tomato) <tomato@tomato.com>
ssb 2048R/1EE2CCE3 2018-09-26


4.使用 gpg --import import他人的公钥
:~/.gnupg/pub$ gpg --import zhongzhendong.asc
gpg: key XXXXXXXX: public key "zhongzhendong <zhongzhendong@XXXX.com>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
:~/.gnupg/pub$

5.使用 gpg --export -a tomato@tomato.com 导出公钥

:~/.gnupg/pub$ gpg --export -a tomato@tomato.com
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

mQENBFurULUBCADy34WNISBAxYlR/St4KXEn6pYqY6tNlqA9bTUjWh76v8qRUt5Z
eNbW8zpnj1f3ZIA9epYzX7g7sfWDlH/zOWH8NhJLJwaJvw+NQRxeq7QV8mCyez55
4n+fjyu8o4KB0ruryXbG6wj3IqWd/X6D/bLMKodvlxyPWu5yo4P0FYcF4MuLzwrq
tSeqay64zNjN2p+4E376yv8suZ92g8Z/IPxk30LWrV1XeLflMJum5G/DWIfZ2EUS
9F1Ok10qBfWmfah3SWZaLAbHAvR0g294WY6b29+Ga0C8dOWYpfpgqFC5b003IxPq
OqamGvkHWaybVlTNhvdZtDvOrnXvCLJzmSHfABEBAAG0KXRvbWF0byAoSSBhbSAg
dG9tYXRvKSA8dG9tYXRvQHRvbWF0by5jb20+iQE4BBMBAgAiBQJbq1C1AhsDBgsJ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gUhS8R18VnlR4TFJ0T
coAYTcg/pHL63HlYQE2JFv55JCyvjT7RoXDlwWcc+ncCNkiukohCmg==
=xGgm
-----END PGP PUBLIC KEY BLOCK-----

6. 使用 gpg -a --export-secret-keys tomato@tomato.com 导出私钥
:~/.gnupg/pub$ gpg -a --export-secret-keys tomato@tomato.com
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: GnuPG v1

lQPGBFurULUBCADy34WNISBAxYlR/St4KXEn6pYqY6tNlqA9bTUjWh76v8qRUt5Z
eNbW8zpnj1f3ZIA9epYzX7g7sfWDlH/zOWH8NhJLJwaJvw+NQRxeq7QV8mCyez55
4n+fjyu8o4KB0ruryXbG6wj3IqWd/X6D/bLMKodvlxyPWu5yo4P0FYcF4MuLzwrq
tSeqay64zNjN2p+4E376yv8suZ92g8Z/IPxk30LWrV1XeLflMJum5G/DWIfZ2EUS
9F1Ok10qBfWmfah3SWZaLAbHAvR0g294WY6b29+Ga0C8dOWYpfpgqFC5b003IxPq
OqamGvkHWaybVlTNhvdZtDvOrnXvCLJzmSHfABEBAAH+BwMCzhJA4S5uADVgprnG
B9PA/aQsrsl8iP0rQnnrIiDamAXiv7TLuLzYBKEkkWVaa92fIVwOQWylfzsRK6FR
21T2W81NClLsqHS8ESh/CU8znb6BBLCgUE8d+v49HSXpnnn2IValtHjdqamfA/77
As9FAdKiS04PrxlLDiCy83NHf54zRqRw2NIsCQ+RNDtDcvHt6l2mowh67N0ZBv4z
WM+82mLIUSEMRHlSdFO3rIamsy9wgq8vCj1OrjCBtMdSdWB5teLpAEXVWpspjZ4H
Zsqq8k7hdDB2AIPpiacA+ERir3+RluP61SKYaR3EWr9BLl8ubQ5xWziy4EdkyCEg
1zghRj9dZCiFUQT9TJGQqMo+2ra9FmNVqP83uy2SmCU7ZYLpDXeaUbhc/EEFVf3D
vRziZYtX2rwHwwjUlywM1r8KbBH5o/1veI03RHDQAiEidaZvq/WkkEvTRvGNIIrf
POsYv29IiA/yH2XXjEuU//xZ2Ho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K6BC+SNmXmusabZy1ZUj3uCM7NUFPksAMR9T1wPlKjNbsyZK
xGU3GeCpK/eIAwNodcL4fmMVDMfU2nelYlXUmCNDE7UVsVFBRz0zp4kBHwQYAQIA
CQUCW6tQtQIbDAAKCRAO7ZC6SMcnMACAB/9uy8+m9TnM6ILypJFr/ITh0+u+zdDG
D/hil6WY/+nWv4G+RV5agupa6opTaQx4Ja7mv2kGEA5Z0dcyTldGKAJx39pa7Y4e
1eiRfJfLG4vcqKderXdpG5fQqdqOi8ykKYY4pFwz5mM7MpWy2toznv3iR49qm8wS
S4lv4KGAj3hzHXEehAZIHpr+yM90qfkLny/hSSVzL4VNoQafb+PGZJUfLAhZSiRK
/ZD5iZ0l/rP1H50e9Mx71XQSwFcqHb1/QpL4CBxR6qhW9BJgmBSFLxHXxWeVHhMU
nRNygBhNyD+kcvrceVhATYkW/nkkLK+NPtGhcOXBZxz6dwI2SK6SiEKa
=JIbn
-----END PGP PRIVATE KEY BLOCK-----


7. 使用 gpg -s 通过非对称加密(就是通过生成的private key加密)。

:~$ gpg -s man_as.txt

You need a passphrase to unlock the secret key for
user: "tomato (I am tomato) <tomato@tomato.com>"
2048-bit RSA key, ID 48C72730, created 2018-09-26

gpg: gpg-agent is not available in this session
Enter passphrase: ==>输入生成key时输入的密码
:~$
生成加密文件 man_as.txt.gpg

使用gpg man_as.txt.gpg 解密文件
:~$ gpg man_as.txt.gpg
File `man_as.txt' exists. Overwrite? (y/N) ==>输入N
Enter new filename:1.txt ==>输入新的文件名
gpg: Signature made Wed 26 Sep 2018 06:00:17 PM CST using RSA key ID 48C72730
gpg: Good signature from "tomato (I am tomato) <tomato@tomato.com>"
:~$

转载于:https://www.cnblogs.com/syyxy/p/9711343.html

GitHub 加速计划 / li / linux-dash
10.39 K
1.2 K
下载
A beautiful web dashboard for Linux
最近提交(Master分支:2 个月前 )
186a802e added ecosystem file for PM2 4 年前
5def40a3 Add host customization support for the NodeJS version 4 年前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐