GnuPG or GPG is Gnu version of Open PG standard implementation. It is very popular especially at personal use for mails etc. Here I will look basic usage of gpg2 in Linux command line interface. gpg2 is the second major version of gpg.
GnuPG或GPG是Open PG标准实现的Gnu版本。 它非常流行,尤其是在个人用于邮件等方面。在这里,我将介绍Linux命令行界面中gpg2的基本用法。 gpg2是gpg的第二个主要版本。
创建/生成私密GPG密钥 (Create/Generate Private GPG Keys)
Here we will create public and private keys for key-ring. Required information asked while certificate generation process. Real name and Email address is given by user and then to encrypt these public and private keys and password is created
在这里,我们将为密钥环创建公用密钥和专用密钥。 证书生成过程中询问的必需信息。 用户提供真实姓名和电子邮件地址,然后对这些公钥和私钥进行加密,并创建密码
$ gpg2 --key-gen
During generation of the GPG Private Keys we will be asked for Real Name
and Email
. After providing this information we will need to enter a passphrase which will be used to encrypt our GPG Private Key. Generation of the private key requires some randomness which may take some time according to the situation. After keys are generated their serial number are provided.
在生成GPG私钥的过程中,我们将要求您提供Real Name
和Email
。 提供此信息后,我们需要输入密码,该密码将用于加密我们的GPG私钥。 私钥的生成需要一定的随机性,根据情况可能会花费一些时间。 生成密钥后,将提供其序列号。
列出现有的PGP密钥 (List Existing PGP Keys)
It can be auto completed by using tab as you can see in first command. In the second command we list existing public keys in keyring. We will provide --list-key
option like below.
如您在第一个命令中所见,可以通过使用制表符来自动完成该操作。 在第二个命令中,我们列出了密钥环中现有的公共密钥。 我们将提供--list-key
选项,如下所示。
$ gpg2 --list-key
We can see that keys are stored in the user home directory .gnupg
directory. Some information like Valid
etc also provided during the listing of the keys.
我们可以看到密钥存储在用户主目录.gnupg
目录中。 在列出密钥期间还提供了诸如Valid
等的一些信息。
签名PGP密钥 (Sign PGP Key)
To sign the data with the specific key not default. Here the --default-key
parameter is looked in keyring in fingerprint, name, email etc. If you want signature apart from data use -b option. We will provide İsmail
as default key with the --default-key
option. We will also provide the data with the -s
option.
使用特定密钥签名数据不是默认值。 在此,-- --default-key
参数在指纹,名称,电子邮件等的密钥环中查找。如果要除数据以外的签名,请使用-b选项。 我们将提供İsmail
作为默认密钥以及--default-key
选项。 我们还将为数据提供-s
选项。
$ gpg2 --default-key İsmail -s test
We will also asked for passphrase to decrypt and use our private key which is create in the previous step.
我们还将要求密码解密并使用在上一步中创建的私钥。
列出秘密钥匙(List Secret Keys)
To see private keys and related info like fingerprint. We will use --list-secret-keys
option for this.
查看私钥和相关信息,例如指纹。 我们将为此使用--list-secret-keys
选项。
$ gpg2 --list-secret-keys
验证签名的PGP文件(Verify Signed PGP File)
The main usage aim of PGP is verifying file whether they are signed accordingly. We can use --verify
option by providing the file name. We will verify the gpg file named data.gpg
.
PGP的主要用途是验证文件是否已相应签名。 我们可以通过提供文件名来使用--verify
选项。 我们将验证名为data.gpg
的gpg文件。
$ gpg2 --verify data.gpg
导出键(Export Keys)
Some time we may need to use existing key in different systems. We have to export these keys into a file. To export existing keyring and use in other systems. We will export existing keys into file name mykeys
有时我们可能需要在不同系统中使用现有密钥。 我们必须将这些密钥导出到文件中。 导出现有密钥环并在其他系统中使用。 我们将现有密钥导出到文件名mykeys
$ gpg2 --export > mykeys
如何使用GPG创建,列出密钥和签名文件? 信息图 (How To Use GPG To Create, List Keys and Sign Files? Infographic)
翻译自: https://www.poftut.com/how-to-use-gpg-to-create-list-keys-and-sign-files/