本页详细讲述了如何使用 Fedora 自带的工具创建 GPG 密钥,以及作为一名 Fedora 贡献人员如何管理您的密钥。
创建 GPG 密钥
在 GNOME/MATE 桌面环境上创建
首先请安装 Seahorse 工具,该工具将会使得您管理 GPG 密钥更方便。从主菜单选择 应用程序 > 添加/删除程序。选择搜索标签并输入 seahorse。勾上 seahorse 软件包旁边的复选框并点击 应用 即可完成安装。您也可以使用命令行安装安装 Seahorse:su -c "yum install seahorse"
.
欲创建一个密钥,打开 应用程序 > Accessories 菜单并选择 Passwords and Encryption Keys,随后会启动 Seahorse。
从 文件 菜单选择 新建... 然后选择 PGP Key 并点击 继续。输入您的全名,邮件地址和可选的一些个人描述(e.g.: John C. Smith, jsmith@example.com, The Man)。点击 创建。一个对话框会显示并询问该密钥的密码短语。输入完毕后点击 OK 即可完成创建。
To find your GPG key ID click on the My Personal Keys tab and look in the Key ID column next to the newly created key. In most cases, if you are asked for the key ID, you should prepend "0x" to the key ID, as in "0x6789ABCD".
Now you should make a backup of your private key.
在 KDE 桌面环境上创建
从主菜单 工具 > PIM > KGpg 启动 KGpg。如果您从未使用过,程序将会带您一步步完成创建。
A dialog box appears prompting you to create a new key pair. Enter your name, email address, and an optional comment. You can also choose an expiration time for your key, as well as the key strength (number of bits) and algorithms. The next dialog box prompts you for your passphrase. At this point, your key appears in the main KGpg window.
欲寻找您的 GPG 密钥 ID,请将目光转向新创建的密钥旁边的 密钥 ID 一栏。绝大多数情况下,如果您被询问密钥 ID,您应该输入的是在刚才看到的那一栏的字符串加上 "0x" 的新字符串,比如 "0x6789ABCD"。
现在您只需要 备份 一下您的私钥即可。
使用命令行创建
使用下列命令:
gpg --gen-key
该命令将会生成一个包含公钥和私钥的密钥对。其他人使用您发布的公钥来验证或解密您的加密信息。将 公钥 尽可能的发给别人,尤其是那些您需要发送加密信息给他们的人,比如邮件列表。例如 Fedora 文档项目,就会要求所有人员在 [DocsProject/SelfIntroduction|自我介绍]] 里提供自己的公钥。
A series of prompts directs you through the process. Press the Enter key to assign a default value if desired. The first prompt asks you to select what kind of key you prefer:
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?
绝大多数情况下默认即可。A RSA/RSA key allows you not only to sign communications, but also to encrypt files.
下一步,选择密钥大小:
RSA keys may be between 1024 and 4096 bits long. What keysize do you want? (2048)
还是默认的即可。针对绝大多数用户,默认的就是非常强的安全级别。
下一步,选择密钥到期时间。这里建议您选择一个到期时间而不是默认的 none.。If, for example, the email address on the key becomes invalid, an expiration date will remind others to stop using that public key.
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)
Entering a value of 1y
, for example, makes the key valid for one year. (You may change this expiration date after the key is generated, if you change your mind.)
Before the gpg
program asks for signature information, the following prompt appears:
Is this correct (y/n)?
Enter y
to finish the process.
Next, enter your name and email address. Remember this process is about authenticating you as a real individual. For this reason, include your real name. Do not use aliases or handles, since these disguise or obfuscate your identity.
Enter your real email address for your GPG key. If you choose a bogus email address, it will be more difficult for others to find your public key. This makes authenticating your communications difficult. If you are using this GPG key for self-introduction on a mailing list, for example, enter the email address you use on that list.
Use the comment field to include aliases or other information. (Some people use different keys for different purposes and identify each key with a comment, such as "Office" or "Open Source Projects.")
At the confirmation prompt, enter the letter O to continue if all entries are correct, or use the other options to fix any problems.
Finally, enter a passphrase for your secret key. The gpg
program asks you to enter your passphrase twice to ensure you made no typing errors.
Finally, gpg
generates random data to make your key as unique as possible. Move your mouse, type random keys, or perform other tasks on the system during this step to speed up the process. Once this step is finished, your keys are complete and ready to use:
pub 1024D/1B2AFA1C 2005-03-31 John Q. Doe (Fedora Docs Project) <jqdoe@example.com> Key fingerprint = 117C FE83 22EA B843 3E86 6486 4320 545E 1B2A FA1C sub 1024g/CEA4B22E 2005-03-31 [expires: 2006-03-31]
The key fingerprint is a shorthand "signature" for your key. It allows you to confirm to others that they have received your actual public key without any tampering. You do not need to write this fingerprint down. To display the fingerprint at any time, use this command, substituting your email address:
gpg --fingerprint jqdoe@example.com
Your "GPG key ID" consists of 8 hex digits identifying the public key. In the example above, the GPG key ID is 1B2AFA1C. In most cases, if you are asked for the key ID, you should prepend "0x" to the key ID, as in "0x1B2AFA1C".
Now you should make a backup of your private key.
备份
在 GNOME/MATE 桌面环境上备份
Right-click your key and select Properties. Select the Details tab, and Export, next to the Export Complete Key label. Select a destination filename and click Save.
Store the copy in a secure place, such as a locked container. Now you are ready to make your public key available to others .
Making a Key Backup Using the KDE Desktop
Right-click your key and select Export Secret Key. At the confirmation dialog, click Export to continue, then select a destination filename and click Save.
Store the copy in a secure place, such as a locked container. Now you are ready to make your public key available to others .
Making a Key Backup Using the Command Line
Use the following command to make the backup, which you can then copy to a destination of your choice:
gpg --export-secret-keys --armor jqdoe@example.com > jqdoe-privkey.asc
Store the copy in a secure place, such as a locked container. Now you are ready to make your public key available to others .
让您的公钥被公众使用
When you make your public key available to others, they can verify communications you sign, or send you encrypted communications if necessary. This procedure is also known as exporting.
You should now export your key using GNOME , KDE , or the command line . You can also copy your key manually to a file if you wish to email it to individuals or groups.
在 GNOME 桌面环境上导出
Export the key to a public keyserver where other project members can obtain it. Right-click the key and select Sync and Publish Keys... (or in the seahorse menu bar click on the Remote menu and select Sync and Publish Keys...). Click Key Servers, select hkp://subkeys.pgp.net:11371 in the Publish Keys To combobox, click Close and then Sync.
You can now read more about safeguarding your key or use your browser to go back to a previous page.
Exporting a GPG Key Using the KDE Desktop
After your key has been generated, you can export the key to a public keyserver by right-clicking on the key in the main window, and selecting Export Public Keys. From there you can export your public key to the clipboard, an ASCII file, to an email, or directly to a key server. Export your public key to the default key server.
You can now read more about safeguarding your key or use your browser to go back to a previous page.
使用命令行导出
Use the following command to send your key to a public keyserver:
gpg --keyserver hkp://subkeys.pgp.net --send-key KEYNAME
For KEYNAME, substitute the key ID of your primary keypair.
You can now read more about safeguarding your key or use your browser to go back to a previous page.
手工复制一个公钥
如果要向某人提供或发送密钥的文件副本,请使用此命令将其写入ASCII文本文件:
gpg --export --armor jqdoe@example.com > jqdoe-pubkey.asc
你现在可以 阅读更多关于保护密钥的信息 或使用你的浏览器返回上一页。
保护您的私钥
像对待任何非常重要的文档或重要的钥匙一样对待你的密钥。 (有些人总是将他们的密钥放在他们的身上,无论是在磁性还是闪存上。)如果你丢失了密钥,你将无法进行通信或打开发送给你的加密信息。
撤销GPG密钥
当你撤销你的密钥权限时,你需要从所有使用它的位置移处。“只有在它被泄露或丢失,或者你忘记了密码时,你需要这样做。”
生成撤销证书
当你创建了一对密钥时,还应创建密钥的吊销证书。如果你稍后颁发吊销证书,它会通知其他人公钥不可用。用户仍然可以使用撤销的公钥来验证旧签名,但不会加密消息。只要你仍然可以访问私钥,以前收到的消息仍然可以解密。如果你忘记了密码,你将无法解密此加密信息。
gpg --output revoke.asc --gen-revoke KEYNAME
如果不使用--output
选项, 证书会正常输出。
For KEYNAME, substitute either the key ID of your primary keypair or any part of a user ID that identifies your keypair. Once you create the certificate (the revoke.asc
file), you should protect it. If it is published by accident or through the malicious actions of others, the public key will become unusable. It is a good idea to write the revocation certificate to secure removable media or print out a hard copy for secure storage to maintain secrecy.
撤销密钥
gpg --import revoke.asc
一旦你在本地撤销密钥,你应该将撤销的证书发送到密钥服务器,无论密钥是否最初是以哪种方式发出的。 通过服务器分发有助于其他用户快速意识到密钥已被泄露。
使用以下命令导出到密钥服务器:
gpg --keyserver subkeys.pgp.net --send KEYNAME
For KEYNAME, substitute either the key ID of your primary keypair or any part of a user ID that identifies your keypair.
访问 GPG 使用 页面了解如何使用您的 GPG 密钥。