GnuPG Gentoo 使用者指南

http://tech.ddvip.com   2006年08月26日    社区交流

本文详细介绍GnuPG Gentoo 使用者指南

内容简介:这篇指南教您怎么使用 GnuPG - 一个安全的加密工具。

  1. 介绍


  您可以在这篇指南中得到什么? 

  这篇指南假设您对公开金钥密码、加密、以及数位签章很熟悉。如果不是,请先阅读 GnuPG handbook 的第二章。

  这篇指南将教导您如何安装 GnuPG、如何建立自己的钥匙对、如何将钥匙加入钥匙炼、如何将公开金钥放至金钥伺服器,以及如何 (签章/加密)/(验证/解密) 您传送/收到的讯息。您也会学到如何将本机电脑的档案加密,让别人不能随意阅读它们的内容。

  安装需要的软体 

  最基本的,您必须先 emerge gnupg,如果您需要有个可以用 GnuPG 的邮件用户端,您可以使用 pine (emerge pinepgp)、mutt (emerge mutt)、 Mozilla/Netscape Mail、evolution (evolution 是以 GNOME 来模仿 Microsoft Outlook 的 MUA)、和 KDE 自己的 KMail (KMail 是 kdenetwork 套件的一部份)。

  如果您使用 KDE,那么 Kgpg 应该会很讨人喜爱。这个小程式让您建立钥匙对、汇入 ASCII 钥匙、对汇入的钥匙签名、汇出钥匙、以及其他一些功能 (它没有将钥匙汇入金钥伺服器的功能,不过您会学到怎样从指令模式做这个动作)。

  2. 产生您的金钥并且将它加入公开钥匙炼


  建立您的金钥 

  要建立您的金钥,请执行 gpg --gen-key。您第一次执行的时候,它会建立几个目录;再执行一次即可建立钥匙:

  代码 2.1: 钥匙产生的过程

#gpg --gen-key
gpg (GnuPG) 1.0.7; Copyright (C) 2002 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)
  (4) ElGamal (sign and encrypt)
  (5) RSA (sign only)
  Your selection? 1

  您可以在这里选择金钥的种类。大部份的使用者会选预设的 DSA 和 ElGamal。然后是金钥的长度,记得数字越大越好,但是不要用超过 2048 bit 的 DSA/ElGamal 金钥。一般来说,1024 对加签/加密 e-mail 已经很够用了。

  在长度之后,您要选金钥的保存期限。在这里越小越好,但是一般使用者可以选永不过期或一至二年的期限。

  代码 2.2: 选择金钥长度

DSA keypair will have 1024 bits.
About to generate a new ELG-E keypair.
       minimum keysize is 768 bits
       default keysize is 1024 bits
  highest suggested keysize is 2048 bits
  What keysize do you want? (1024) 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) 0
Key does not expire at all

  现在您可以输入一些有关个人的资讯。如果您想将公开金钥传送给别人,则您可以在这里使用真正的邮件位置。

  代码 2.3: 输入个人资讯

Is this correct (y/n)? y
You need a User-ID to identify your key; the software constructs the user id
from Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
Real name: John Doe
Email address: john@nowhere.someplace.flick
Comment: The Real John Doe
You selected this USER-ID:
"John Doe (The Real John Doe) <john@nowhere.someplace.flick>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
Enter passphrase:

  现在输入两次您的钥匙密码。用个难被破解的密码是个好主意。如果某个人得到了您的私密金钥并且破解了您的密码,他就可以用您的名义签章,而且大家都会认为那真的是您签的名。

  然后,GnuPG 会产生您的密码。移动滑鼠或在背景拨放 mp3 可以加速处理过程,因为它们可以制造随机的资料。

  产生撤回的认证 

  重要:这个步骤非常重要,而且您应该马上做。

  在您建立一组钥匙之后应该马上建立撤回认证。这允许您在某些麻烦事 (某人取得了您的私密金钥/密码) 发生的时候撤回这付钥匙。

  代码 2.4: 产生撤回认证

#gpg --list-keys
/home/humpback/.gnupg/pubring.gpg
---------------------------------
pub 1024D/75447B14 2002-12-08 John Doe (The Real John Doe) <john@nowhere.someplace.flick>
sub 2048g/96D6CDAD 2002-12-08
bash-2.05a$ gpg --output revoke.asc --gen-revoke 75447B14
sec 1024D/75447B14 2002-12-08  John Doe (The Real John Doe) <john@nowhere.someplace.flick>
Create a revocation certificate for this key? y
Please select the reason for the revocation:
 0 = No reason specified
 1 = Key has been compromised
 2 = Key is superseded
 3 = Key is no longer used
 Q = Cancel
(Probably you want to select 1 here)
Your decision? 1
Enter an optional description; end it with an empty line:
> Someone cracked me and got my key and passphrase
>
Reason for revocation: Key has been compromised
Someone cracked me and got my key and passphrase
Is this okay? y
You need a passphrase to unlock the secret key for
user: "John Doe (The Real John Doe) <john@nowhere.someplace.flick>"
1024-bit DSA key, ID 75447B14, created 2002-12-08
ASCII armored output forced.
Revocation certificate created.
Please move it to a medium which you can hide away; if Mallory gets
access to this certificate he can use it to make your key unusable.
It is smart to print this certificate and store it away, just in case
your media become unreadable. But have some caution: The print system of
your machine might store the data and make it available to others!

  gpg --list-keys 指令会列出您的公开钥匙炼。您可以使用它来查看您可以建立撤回认证的钥匙 ID。现在是个把所有 .gnupg 目录以及它们的 ASCII 铠甲 (revoke.asc) 复制到其他安全的媒体 (您放在保险柜的磁碟片或光碟片上) 的好机会。注意 revoke.asc 可以撤销您的金钥并且让它们以后不能再被使用。

  注释: 如果您有数个 e-mail 地址而您想要使用同一把钥匙,您可以执行 gpg --edit-key YOUR_ID 然后使用 adduid 指令。它会问您的名称、电子邮件以及您会使用的第二个 ID 的注解。

  汇出金钥 

  想汇出您的钥匙,您可以输入 gpg --armor --output john.asc --export john@nowhere.someplace.flick。您几乎总是可以使用钥匙的 ID 或某些可以指出钥匙的资讯 (在这里我们使用电子邮件地址)。现在他可以把 john.asc 这把公开金钥传送给他的朋友,或是放在某个大家都可以安全拿到的地方。

  汇入金钥 

  想在公开钥匙炼中加入档案,您必须先汇入它,然后检查金钥的指纹。在您确认了指纹之后您应该核对它。

  注释: 您应该小心的核对这些金钥。这是公开金钥编码的弱点之一。

  现在我们会加入 Luis Pinto (我一个朋友) 的公开金钥到我们的公开钥匙炼。在打电话问到她的金钥指纹以后,我将把指纹根和使用 fpr 指令产生的指纹比对。因为这个金钥是可靠的,所以我将它加入公开钥匙炼。同时,Lius 的钥匙会在 2003-12-01 过期,所以他问我要不要在过期的同时让我的加签过期。

  代码 2.5: Importing and signing keys

#gpg --import luis.asc
gpg: key 462405BB: public key imported
gpg: Total number processed: 1
gpg:        imported: 1
humpback@sam humpback $ gpg --list-keys
/home/humpback/.gnupg/pubring.gpg
---------------------------------
pub 1024D/75447B14 2002-12-08 John Doe (The Real John Doe) <john@nowhere.someplace.flick>
sub 2048g/96D6CDAD 2002-12-08
pub 1024D/462405BB 2002-12-01 Luis Pinto <lmpinto@student.dei.uc.pt>
  uid              Luis Pinto <lmpinto@dei.uc.pt>
sub 4096g/922175B3 2002-12-01 [expires: 2003-12-01]
humpback@sam humpback $ gpg --edit-key lmpinto@dei.uc.pt
gpg (GnuPG) 1.0.7; Copyright (C) 2002 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: checking the trustdb
gpg: checking at depth 0 signed=0 ot(-/q/n/m/f/u)=0/0/0/0/0/1
pub 1024D/462405BB created: 2002-12-01 expires: 2003-12-01 trust: -/-
sub 4096g/922175B3 created: 2002-12-01 expires: 2003-12-01
(1) Luis Pinto <lmpinto@dei.uc.pt>
(2). Luis Pinto <lmpinto@student.dei.uc.pt>
Command> fpr
pub 1024D/462405BB 2002-12-01 Luis Pinto <lmpinto@dei.uc.pt>
       Fingerprint: F056 3697 ADE3 CF98 B80B 8494 0AD3 E57B 4624 05BB
Command> sign
Really sign all user IDs? y
pub 1024D/462405BB created: 2002-12-01 expires: 2003-12-01 trust: -/-
       Fingerprint: F056 3697 ADE3 CF98 B80B 8494 0AD3 E57B 4624 05BB
     Luis Pinto <lmpinto@dei.uc.pt>
     Luis Pinto <lmpinto@student.dei.uc.pt>
This key is due to expire on 2003-12-01.
Do you want your signature to expire at the same time? (Y/n) Y
How carefully have you verified the key you are about to sign actually belongs
to the person named above? If you don't know what to answer, enter "0".
  (0) I will not answer. (default)
  (1) I have not checked at all.
  (2) I have done casual checking.
  (3) I have done very careful checking.
  Your selection? 3
Are you really sure that you want to sign this key
with your key: "John Doe (The Real John Doe) <john@nowhere.someplace.flick>"
I have checked this key very carefully.
Really sign? y
You need a passphrase to unlock the secret key for
user: "John Doe (The Real John Doe) <john@nowhere.someplace.flick>"
1024-bit DSA key, ID 75447B14, created 2002-12-08
Command> check
uid Luis Pinto <lmpinto@dei.uc.pt>
sig!3    462405BB 2002-12-01  [self-signature]
sig!3    75447B14 2002-12-08  John Doe (The Real John Doe) <john@nowhe
uid Luis Pinto <lmpinto@student.dei.uc.pt>
sig!3    462405BB 2002-12-01  [self-signature]
sig!3    75447B14 2002-12-08  John Doe (The Real John Doe) <john@nowhe

  3. 与金钥伺服器交换钥匙


  传送钥匙至金钥伺服器 

  现在您有了自己的钥匙,将它传送到世界性的金钥伺服器大概是个好主意。世界上有很多金钥伺服器并且会自动在它们之间交换金钥。在这里我们将把 Luis 的钥匙送到 pgp.mit.edu 伺服器。这使用 HTTP,所以如果您需要使用 HTTP 代理伺服器别忘了先设定它 (export http_proxy=http://proxy_host:port/)。传送金钥的指令是: gpg --keyserver pgp.mit.edu --keyserver-options honor-http-proxy --send-key john@nowhere.someplace.flick。如果您不需要使用 HTTP 代理伺服器,则您可以拿掉 --keyserver-options honor-http-proxy 的部份。

  您也可以传送其他您签过名的钥匙到金钥伺服器。我们可以将 Luis Pinto's 的钥匙送至金钥伺服器。这样的话,某个信任您金钥的人可以使用您信任 Luis 的钥匙的签章。

  从金钥伺服器取得钥匙 

  现在我们将找寻 Gustavo Felisberto 的金钥并将它加入 John Doe 的钥匙炼 (只是为了确定您有注意到 Gustavo Felisberto 是写了这篇指南的人 :) )。

  代码 3.1: Searching keys from keyservers

#gpg --keyserver pgp.mit.edu --keyserver-options honor-http-proxy \
  --search-keys humpback@felisberto.net
gpg: searching for "humpback@felisberto.net" from HKP server pgp.mit.edu
Keys 1-5 of 5 for "humpback@felisberto.net"
(1)  Gustavo Felisberto (apt-get install anarchy) <humpback@felisberto.net> 1024
   created 2002-12-06, key B9F2D52A
(2)  Gustavo Felisberto <humpback@altavista.net> 1024
   created 1999-08-03, key E97E0B46
(3)  Gustavo A.S.R. Felisberto <humpback@altavista.net> 1024
   created 1998-12-10, key B59AB043
(4)  Gustavo Adolfo Silva Ribeiro Felisberto <humpback@altavista.net> 1024
   created 1998-08-26, key 39EB133D
(5)  Gustavo Adolfo Silva Ribeiro Felisberto <humpback@altavista.net> 1024
   created 1998-06-14, key AE02AF87
   Enter number(s), N)ext, or Q)uit >1
gpg: requesting key B9F2D52A from HKP keyserver pgp.mit.edu
gpg: key B9F2D52A: public key imported
gpg: Total number processed: 1
gpg:        imported: 1

  如您从伺服器回应看到的,我传送了好些个金钥到伺服器。可是我目前只使用 B9F2D52A。现在 John Doe 可以取得这把钥匙并且信任地将它签章。

  4. 和文件一起使用


  加密以及签名 

  让我们假设您现在想送份档案给 Lius。您可以将它加密、签名、或又加密又签名。加密表示只有 Luis 能够开启它。而签章表示这份档案真的是您建立的。

  接下了的三个命令会帮您做这些事,加密、签名、和又加密又签名。

  代码 4.1: 检查档案中的金钥并将它解码

#gpg --output doc.gpg --encrypt --recipient lmpinto@dei.uc.pt doc_to_encrypt
#gpg --output doc.gpg --sign --recipient lmpinto@dei.uc.pt doc_to_sign
#gpg --output doc.gpg --encrypt --sign --recipient \
    lmpinto@dei.uc.pt doc_to_encrypt_and_sign

  这会建立二进位的加密档。如果您想要建立 ASCII 档案,请在命令前面加上 --clearsign 选项。

  解密以及验证签名 

  设想您取得了一篇给您的加密文件,将它解密的指令是 gpg --output document --decrypt encrypted_doc.gpg。这会将文件解密并且检查签章 (如果有的话)。

  5. GnuPG 介面


  kgpg 

  kgpg 是个很好的 GNUPG 图形画界面。在主主视窗中,您可以直接贴上您想要签名或加密的文字,而您可以直接贴上想要解密的 ASCII 格式加密文字。


  图5.1


  在这个 kgpg 主视窗中您可以看见一个贴满了 ASCII 格式的加密档案。您可以在这里将它解密 (您必须提供您的密码),将其他档案加密,贴上要签名的文字...


  图5.2


  现在您可以看到金钥管理视窗。从这里我们看到了 John Doe 的好钥匙。两把从 Gustavo 和 Luis 来的认证的钥匙,以及从 Daniel Robbins 得到尚未信任的钥匙 (我还没打电话给他确认指纹 :) )。


  图5.3


  图5.4


  Mozilla Enigmail 

  Mozilla 从 1.0 版以后有附上 Enigmail,一个设定简单的邮件用户端插件。您只要去 Preferences -> Privacy & Security -> Enigmail,并且在那里输入您金钥的 e-mail 位置就可以了。

  附上没有认证的 pgp 或 gpg 签章的邮件会以一支断掉的笔标注,其他有优良签章的会看起来像一支完好无缺的笔。Enigmail 还有从金钥伺服器取得钥匙的功能,不过如果有发生问题它会秀出一则非常诡异的讯息 (您应该还记得怎么使用文字指令吧?)。

  KMail 

  Kmail 也很好设定。我将会贴上几张表示该怎样设定它的图。基本上您必须告诉 KMail 要使用 GPG 以及要用那把金钥签名。

  6. 最后的想法、荣誉榜、以及版权声明


  一些问题 

  我有些把照片放进金钥的问题。检查您使用的版本,如果您使用 GnuPG 1.2.1-r1 或以上,您应该没什么问题。比较旧的版本也许有问题,而且大部份的伺服器不喜欢有附照片的钥匙。

  这篇文章还缺什么? 

  Gpg 是个非常复杂的工具,它可以让您做到许多这里没有提到的事情。这篇文件是否为了那些 GnuPG 新手写的。要得到更多资讯,您应该查阅 GnuPG 网站

  我没有介绍例如 pgp4pine、gpgpine、evolution 以及也许 Windows 工具之类的东西,也许以后会再陆续添增。

  荣誉榜 

  John Michael Ashley 的 GnuPG Handbook 写的非常美妙。对新手来说是很好的参考书。

  所有 #gentoo-doc 团队中的人。

  追踪我隐私的 Tiago Serra。

  版权声明 

  Copyright by Gustavo Felisberto. Gentoo Technologies Inc. is allowed to publish this document as it sees fit.

  注释:(译注:此段不译。)

责编:豆豆技术应用

正在加载评论...