GPG 加密软件使用在RHEL5 和Centos5

 

  最近在研究加密软件for linux,最后发现PGP,Turecrypt and GPG 这三加密软件很不错,当然它们也各有各的优缺点哦,PGP是一收费软件,而且现在只支持MS and Mac os,要到明年第一季度才能支持LINUX,所以不谈(因为现在老板最想节约cost );至于GPG加密性能都很不错,而且关键又是free,但不支持folder and disk encrypt , 所以下面我会详细讨论它;最后一个Turecrypt加密也是free soft,它可以对目录  and 磁盘加密,配置也very easy, 所以就没有写文档(有兴趣朋友可以Google or contact me )。以下是GPG  soft guide:
 
1.首先我们要看当前的Linux系统上是否已经了gnupg软件,对于Red Hat linux7.0 版本之后会自动地安装此软件;我们输入下列命令查看本机是否安装
  Linux$rpm-qa│grep gnupg
  gnupg-1.4.5-11
  说明已经安装
  2.在安装完gnupg软件包后,我们需要做的是生成一对密钥
  Linus$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 and ELGamal 算法)
   DSA keypair will have 1024 bits.
ELG-E keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 1024  (我选择2048 加密长度)
   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 什么时候过期,我选择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: Haiquan
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
   You need a Passphrase to protect your secret key.
 
Enter passphrase: Chq@123 (输入real name, email address, and passphrase, 可以把passphrase 看作保护私钥的密码)
   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.
+++++..++++++++++.+++++++++++++++.+++++++++++++++.+++++.+++++++++++++++++++++++++.+++++++++++++++++++++++++++++++++++.++++++++++++++++++++..++++++++++.+++++>...++++++++++>+++++....>+++++............<...+++++............................>..+++++......................<+++++.............+++++^^
 3. 我们可以下列命令查看自己刚才建立的私钥
  Linux$ gpg-list-secret-keys
  查看自己的公钥
  Linux$ gpg-list-keys
 4. 用同样的方法在另一台机器上安装gpg,并使用下列命令导出公钥 (不一定要用另台机器,可以用另一帐户,只不过两台机器测试明朗一些)
  Linus$ gpg-export>gpgkey.asc
  注:公钥的名字一定要以asc为扩展名,把将这个文件传到你的机器上
 5.在你的机器上使用下列命令将对方的公钥导入
  Linux$ gpg-import gpgkey.asc
  并再次用gpg-list-keys命令看是否成功导入了对方的公钥
    6. 接下来我们用做的就是对这把新导入的公钥签名
  Linux$ gpg-sign-key Haiquan
  注:这里Haiquan应是对方建立密钥的real name
  我们可以利用pgp-list-sigs来查看是否正确地对对方公钥签名了
  采用同样的方法将你的公钥导出传到对方的机器上
 7.这样我们就可以用对方的公钥来加密文件了;首先建立一个文件
  Linux$ eacho this is a test gpg soft encrypt .>encryptfile
 8.用对方的公钥来加密此文件
  Linux$ gpg --encypt -r receiver_public_keyname encryptfile
  receiver_public_keyname在这里应为接收者的公钥名字(Haiquan);执行完毕后,会生成
  加密后的文件encryptfile.asc,我们cat encryptfile.asc输出结果,看看怎样!
     9.将此加密后的文件传到对方机器上,接收方用下命令解密
  gpg -–decrypt encryptfile.asc > encryptfile
  输入正确的passphrase后,会生成解密后的encryptfile文件。
    10.如果需要发送一封既加密又签名的邮件内容,使用下面命令。
  Gpg –se –r receiver_public_keyname filename
    11.接收者收到这样的信件,只需输入:
   gpg –d filename.asc
注: 此文档测试了加密与签名,可能有些乱,如果只知道加密方法,请看这篇文档:
       “GPG encrypt soft guide for LUNIX”

 

你可能感兴趣的:(linux,centos,职场,gpg,休闲,加密软件)