Gpg文件加密:

首先必须装上gnupg包

1生成密钥对:

[root@localhost ~]# gpg --gen-key

gpg (GnuPG) 2.0.14; Copyright (C) 2009 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.

 

请选择您要使用的密钥种类:

   (1) RSA and RSA (default)

   (2) DSA and Elgamal

   (3) DSA (仅用于签名)

   (4) RSA (仅用于签名)

您的选择? 1

RSA 密钥长度应在 1024 位与 4096 位之间。

您想要用多大的密钥尺寸?(2048)

您所要求的密钥尺寸是 2048 位

请设定这把密钥的有效期限。

         0 = 密钥永不过期

      <n>  = 密钥在 n 天后过期

      <n>w = 密钥在 n 周后过期

      <n>m = 密钥在 n 月后过期

      <n>y = 密钥在 n 年后过期

密钥的有效期限是?(0) 0

密钥永远不会过期

以上正确吗?(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>"

 

真实姓名:zhangsan                        //这个地方必须写,是以后的key-id

电子邮件地址:zhangsan@example.com

注释:hahah

您选定了这个用户标识:

    &ldquo;zhangsan (hahah) <zhangsan@example.com>&rdquo;

 

更改姓名(N)、注释(C)、电子邮件地址(E)或确定(O)/退出(Q)?O

您需要一个密码来保护您的私钥。

 

gpg: problem with the agent: Not implemented

我们需要生成大量的随机字节。这个时候您可以多做些琐事(像是敲打键盘、移动

鼠标、读写硬盘之类的),这会让随机数字发生器有更好的机会获得足够的熵数。

我们需要生成大量的随机字节。这个时候您可以多做些琐事(像是敲打键盘、移动

鼠标、读写硬盘之类的),这会让随机数字发生器有更好的机会获得足够的熵数。

gpg: 密钥 F7940F47 被标记为绝对信任

公钥和私钥已经生成并经签名。

 

gpg: 正在检查信任度数据库

gpg: 需要 3 份勉强信任和 1 份完全信任,PGP 信任模型

gpg: 深度:0 有效性:  1 已签名:  0 信任度:0-,0q,0n,0m,0f,1u

pub   2048R/F7940F47 2011-11-09

密钥指纹 = 87C7 E395 E07C 38C5 62FB  6185 A005 9630 F794 0F47

uid                  zhangsan (hahah) <zhangsan@example.com>

sub   2048R/F1C9F981 2011-11-09

2导出公钥:

[root@localhost ~]# gpg --export --armor zhangsan > file.key //张三就是咱们前面讲到的key-id

3导入公钥:

[root@localhost ~]# gpg --import file.key 

gpg: 密钥 F7940F47:&ldquo;zhangsan (hahah) <zhangsan@example.com>&rdquo;未改变

gpg: 合计被处理的数量:1

gpg:           未改变:1

4加密文件:

[root@localhost ~]# gpg --encrypt --armor -r zhangsan install.log

                //看看目录中是不是多了个install.log.asc文件,我们就可以把原来的install.log删除了

rm  -rf   install.log

5解密文件

[root@localhost ~]# gpg --decrypt install.log.asc > install.log

 

您需要输入密码,才能解开这个用户的私钥:&ldquo;zhangsan (hahah) <zhangsan@example.com>&rdquo;

2048 位的 RSA 密钥,钥匙号 F1C9F981,建立于 2011-11-09 (主钥匙号 F7940F47)

 

gpg: 由 2048 位的 RSA 密钥加密,钥匙号为 F1C9F981、生成于 2011-11-09

      &ldquo;zhangsan (hahah) <zhangsan@example.com>&rdquo;

6验证

[root@localhost ~]# head -5 install.log

安装 fontpackages-filesystem-1.41-1.1.el6.noarch

warning: fontpackages-filesystem-1.41-1.1.el6.noarch: Header V3 RSA/SHA256 Signature, key ID fd431d51: NOKEY

安装 m17n-db-1.5.5-1.1.el6.noarch

安装 xml-common-0.6.3-32.el6.noarch

安装 setup-2.8.14-10.el6.noarch