GNU/Linux >> Linux の 問題 >  >> Cent OS

Linux で GPG を使用して PGP キーを生成する方法

Linux で GPG を使用して PGP キーを生成する方法

GNU Privacy Guard アプリケーションを使用すると、情報の暗号化と復号化、公開および秘密暗号化キーの作成、デジタル署名の使用または検証を行うことができます。 GPG は、公開鍵と秘密鍵 (または「秘密」) のペアの使用に基づいています。一方のキーで暗号化されたデータは、もう一方のキーでのみ復号化できます。あなたへのメッセージを暗号化するために、誰かがあなたの公開鍵を使用して、あなたの秘密鍵でのみロックを解除できるメッセージを作成します。情報に署名するには、秘密鍵でロックし、公開鍵でロックを解除することで、誰でもそれがあなたからのものであることを確認できるようにします.

GPG には、利用可能なオプションを微調整する多数の追加オプションがあります。この投稿では、Linux で GPG を使用して PGP キーを生成する方法について説明します。

ステップ 1 :GPG のバージョンを確認してください。

# gpg --help

gpg (GnuPG) 1.4.5
Copyright (C) 2006 Free Software Foundation, Inc.

ステップ 2 :キー生成プロセスを開始します。次のコマンドを入力して、キーの生成を開始します:

gpg --gen-key

Select the type of key

Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)      ## SELECT THIS OPTION
Your selection? 5

Select the key size

RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048

Requested keysize is 2048 bits

Select the expiration time

Please specify how long the key should be valid.
0 = key does not expire                 ## SELECT THIS OPTION
 = key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0) 0

Key does not expire at all

Is this correct? (y/N) y

Enter user name and email

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: 

"[NAME]" (xyz-comment) [USERNAME]@[DOMAIN_NAME].com"

Real name: [Name]
Email address: [USERNAME]@[DOMAIN_NAME].com
Comment: comment
You selected this USER-ID:
"[Name] (comment) [USERNAME]@[DOMAIN_NAME].com"

Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O

Enter passphrase to protect secret key

You need a Passphrase to protect your secret key.

Enter passphrase: *******
Repeat 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.

You may see the following message. If you do, follow the instructions and the key generation process will start automatically.

Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 284 more bytes)

..+++++
...+++++
gpg: key F709C771 marked as ultimately trusted
public and secret key created and signed

gpg: checking the trustdb
gpg: 3 marginal(s) needed. 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0m, 0n, 0f, 1u
pub: 2048R/F709C771 2015-05-27
key fingerprint = BDC2 5293 DB14 C218 D2DA 711C EB0A 564A F709 C771
uid [Name] (comment) [USERNAME]@[DOMAIN_NAME].com

この鍵は暗号化には使用できないことに注意してください。コマンド「–edit-key」を使用することをお勧めします 」 この目的のためにサブキーを生成します。鍵の生成が完了しました。この時点で、署名目的で使用できる公開鍵を使用して、秘密鍵と公開鍵のペアが生成されました。次のステップは、暗号化に使用されるサブキーを追加することです。

ステップ 3 :暗号化用のサブキーを追加します。次のコマンドを入力して、キーの生成を開始します:

# gpg --edit-key '[NAME]'
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.

Secret key is available.

pub 2048R/F709C771 created: 2015-05-27 expires: never usage: SC
trust: ultimate validity: ultimate
[ultimate] (1). [Name] (comment) [USERNAME]@[DOMAIN_NAME].com

Enter the edit-key command

Command> addkey

Key is protected.

Enter the passphrase you specified in step 2

You need a passphrase to unlock the secret key for
user: "[NAME] (comment) [USERNAME]@[DOMAIN_NAME].com"
2048-bit RSA key, ID F709C771, created 2015-05-27

Enter passphrase: *******

user: "[Name] (comment) [USERNAME]@[DOMAIN_NAME].com"
2048-bit RSA key, ID F709C771, created 2015-05-27

Select the type of key

Please select what kind of key you want:
(2) DSA (sign only)
(4) Elgamal (encrypt only)
(5) RSA (sign only)
(6) RSA (encrypt only)              ## SELECT THIS OPTION
Your selection? 6

Select the key size

RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 2048

Requested keysize is 2048 bits

Select the expiration time

Please specify how long the key should be valid.
0 = key does not expire       ## SELECT THIS OPTION
 = key expires in n days
w = key expires in n weeks
m = key expires in n months
y = key expires in n years
Key is valid for? (0) 0

Key does not expire at all
Is this correct? (y/N) Y
Really create? (y/N) Y

多くのランダムなバイトを生成する必要があります。プライム生成中に他のアクション (キーボードで入力する、マウスを動かす、ディスクを使用する) を実行することをお勧めします。これにより、乱数ジェネレーターが十分なエントロピーを獲得できる可能性が高くなります。

次のメッセージが表示される場合があります。その場合は、指示に従ってください。サブキーの生成プロセスが自動的に開始されます。

Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 277 more bytes)

..........+++++
..........+++++

pub 2048R/F709C771 created: 2015-05-27 expires: never usage: SC
trust: ultimate validity: ultimate
sub 2048R/13DA9D02 created: 2015-05-27 expires: never usage: E
[ultimate] (1). [Name] (comment) [USERNAME]@[DOMAIN_NAME].com

Note, pub is for signing (SC), sub is for encryption (E)

Exit the edit-key editor and save your changes

Command> q
Save changes? (y/N) y

暗号化用のサブキーの生成が完了しました。次のステップは、鍵を検証してエクスポートすることです。

ステップ 4 :キーを一覧表示します。次のコマンドを入力して、キーリングのキーを一覧表示します:

# gpg -k
/home/[USERNAME]/.gnupg/pubring.gpg
--------------------------------
pub 2048R/F709C771 2015-05-27
uid Your [NAME] (comment) [USERNAME]@[DOMAIN_NAME].com
sub 2048R/13DA9D02 2015-05-27

ステップ 5 – 公開鍵 (サブ鍵を含む) を ASCII 形式でエクスポートします。次のコマンドを入力して、キーを一覧表示します:

# gpg --armor --output [Name]-pub-sub.asc --export '[Name]'
# cat [NAME]-pub-sub.asc

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.5 (GNU/Linux)

“[.......Removed the PGP KEY...... ]”

-----END PGP PUBLIC KEY BLOCK-----


Cent OS
  1. cPanelを使用してSSHキーを設定する方法

  2. Linuxで証明書署名要求(CSR)を生成する方法

  3. LinuxでPPKファイルをOpenSSHキーに変換し、SSHを使用してログインする方法は?

  1. Linux専用サーバーでSSHキーを生成する方法は?

  2. Linux で GnuPG を使用してファイルを暗号化および復号化する方法

  3. GUI を使用して Linux で PGP キーを作成 (および公開) する方法

  1. CentOS7でSSHキーを生成および設定する方法

  2. Debian10でSSHキーを生成および設定する方法

  3. CentOS8でSSHキーを設定する方法