我們輸入下列指令檢視本機是否安裝
Linux$rpm-qa│grep gnupg gnupg-1.4.5-11 說明已經安裝 接下來生成密鑰
[root@localhost tmp]# 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.
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) 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)
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: kingsoft
Email address: [email protected]
Comment: kingsoft
You selected this USER-ID:
"kingsoft (kingsoft) <[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.
+++++++++++++++++++++++++.++++++++++++++++++++++++++++++..++++++++++..+++++++++++++++.++++++++++.+
+++++++++.++++++++++.++++++++++..++++++++++>++++++++++........................................>+++
++.......<+++++..>+++++<.+++++.>+++++..+++++
We need to generate a lot of random bytes. It is a good idea to perform
++++++++++.+++++++++++++++.++++++++++..++++++++++..++++++++++++++++++++++++++++++++++++++++.+++++.
+++++++++++++++++++++++++..++++++++++.++++++++++.++++++++++>.++++++++++>..+++++>++++
+...........................+++++^^^
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key ECA840EB 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 1024D/ECA840EB 2012-07-02
Key fingerprint = 8090 3DC7 C054 ABD0 C51F 25DC 5FB6 882D ECA8 40EB
uid kingsoft (kingsoft) <[email protected]>
sub 2048g/3DF27DB5 2012-07-02
[root@localhost tmp]# ls
cront.1427 kfs_result
導出公鑰
[root@localhost tmp]# gpg --export --armor kingsoft > gpgkey.pub.asc (kingsoft根據自己前面取的real name 修改)
cront.1427 gpgkey.pub.asc kfs_result
導出私鑰
[root@localhost tmp]# gpg -o seckey.asc --export-secret-keys kingsoft (kingsoft根據自己前面取的real name 修改)
在其他機器上面,上傳gpgkey.pub.asc 與 seckey.asc
[root@localhost tmp]# gpg --import gpgkey.pub.asc
添加信任kingsoft名字
[root@localhost tmp]# gpg --edit-key kingsoft
Secret key is available.
pub 1024D/ECA840EB created: 2012-07-02 expires: never usage: SC
trust: ultimate validity: ultimate
sub 2048g/3DF27DB5 created: 2012-07-02 expires: never usage: E
[ultimate] (1). kingsoft (kingsoft) <[email protected]>
Command> trust
Please decide how far you trust this user to correctly verify other users' keys
(by looking at passports, checking fingerprints from different sources, etc.)
1 = I don't know or won't say
2 = I do NOT trust
3 = I trust marginally
4 = I trust fully
5 = I trust ultimately
m = back to the main menu
Your decision? 5
Do you really want to set this key to ultimate trust? (y/N) y
Command> quit
現在我們在這台機器上進行加密檔案操作
[root@localhost tmp]# cat zk.txt
test
zhangkai
zk.txt
[root@localhost tmp]# gpg -e -r kingsoft zk.txt
[root@localhost tmp]# ls
zk.txt zk.txt.gpg
zk.txt.gpg即是加密後的檔案
現在我們在這台機器上進行解密檔案操作
[root@localhost tmp]# gpg --import seckey.asc
[root@localhost tmp]# gpg -o 123.txt -d zk.txt.gpg (-o 指定解密後的檔案名)