「GnuPG」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(この.serviceをそのまま使うとエラーになるため、英語版の最新版に修正)
(同期)
3行目: 3行目:
 
[[es:GnuPG]]
 
[[es:GnuPG]]
 
[[ru:GnuPG]]
 
[[ru:GnuPG]]
  +
[http://www.gnupg.org 公式サイト] によれば:
[http://www.gnupg.org GnuPG] を使うことでデータや通信を暗号化したり署名することができます。多目的の鍵管理システムであり、あらゆる種類の公開鍵ディレクトリのアクセスモジュールです。
 
  +
  +
:GnuPG は RFC4880(別名 [[Wikipedia:PGP|PGP]])で定義される OpenPGP 標準の完全でフリーな実装です。GnuPG を使うことでデータや通信を暗号化したり署名することができます。多目的の鍵管理システムであり、あらゆる種類の公開鍵ディレクトリのアクセスモジュールです。GnuPG(またの名を GPG)は他のアプリケーションとの簡単に連携できる機能を備えたコマンドラインツールです。豊富なアプリケーションとライブラリが利用可能です。GnuPG のバージョン2は S/MIME と ssh のサポートも含んでいます。
   
 
== インストール ==
 
== インストール ==
   
[[公式リポジトリ]]にある {{Pkg|gnupg}} をインストールしてください。
+
{{Pkg|gnupg}} をインストールしてください。
   
 
gnupg をインストールすると、GnuPG がパスフレーズエントリに使用するシンプルな PIN やパスフレーズエントリダイアログのコレクションである {{Pkg|pinentry}} もインストールされます。''pinentry'' はシンボリックリンク {{ic|/usr/bin/pinentry}} によって決められ、デフォルトでは {{ic|/usr/bin/pinentry-gtk-2}} になります。
 
gnupg をインストールすると、GnuPG がパスフレーズエントリに使用するシンプルな PIN やパスフレーズエントリダイアログのコレクションである {{Pkg|pinentry}} もインストールされます。''pinentry'' はシンボリックリンク {{ic|/usr/bin/pinentry}} によって決められ、デフォルトでは {{ic|/usr/bin/pinentry-gtk-2}} になります。
  +
  +
グラフィカルフロントエンドや GnuPG と連携するプログラムを使いたい場合は[[アプリケーション一覧/セキュリティ#暗号化, 署名, ステガノグラフィー]]を参照してください。
   
 
== 環境変数 ==
 
== 環境変数 ==
21行目: 25行目:
 
{{Note|デフォルトでは、gnupg ディレクトリの[[ファイルのパーミッションと属性|パーミッション]]は ''700'' に設定されており、ディレクトリのファイルのパーミッションは ''600'' に設定されています。ファイルの読み書きやアクセスの権限を持っているのはディレクトリの所有者だけです (''r'',''w'',''x'')。これはセキュリティ上の理由で設定されていることなので変更してはいけません。ディレクトリやファイルがこのセキュリティ対策に従っていない場合、ファイルやホームディレクトリのパーミッションが安全ではないという警告が表示されます。}}
 
{{Note|デフォルトでは、gnupg ディレクトリの[[ファイルのパーミッションと属性|パーミッション]]は ''700'' に設定されており、ディレクトリのファイルのパーミッションは ''600'' に設定されています。ファイルの読み書きやアクセスの権限を持っているのはディレクトリの所有者だけです (''r'',''w'',''x'')。これはセキュリティ上の理由で設定されていることなので変更してはいけません。ディレクトリやファイルがこのセキュリティ対策に従っていない場合、ファイルやホームディレクトリのパーミッションが安全ではないという警告が表示されます。}}
   
=== GPG_AGENT_INFO ===
+
== 設定ファイル ==
   
  +
デフォルトは {{ic|~/.gnupg/gpg.conf}} と {{ic|~/.gnupg/dirmngr.conf}} です。デフォルトの場所を変更したい場合は、{{ic|$ gpg --homedir ''path/to/file''}} と gpg を実行するか {{ic|$GNUPGHOME}} 変数を使って下さい。どんな長いオプションもこのファイルに追加します。2つのダッシュを書かないで、オプションや必要な引数の名前を書いて下さい。スケルトンファイルは {{ic|/usr/share/gnupgl}} にあります。gpg がなんらかの操作のため最初に起動されたとき、~/.gnupg が存在しなければこれらのファイルが ~/.gnupg にコピーされます。[[#参照]] に他の例があります。
{{ic|GPG_AGENT_INFO}} は gpg-agent を示すのに使われます。コロンで区切られた3つのフィールドから成ります:
 
   
  +
== 使い方 ==
# Unix ドメインソケットのパス
 
# gpg-agent の PID
 
# プロトコルのバージョン
 
   
  +
{{Note|コマンドに ''{{ic|<user-id>}}'' が必要なときは、鍵 ID、指紋、名前やメールアドレスの一部などを指定できます。これについて GnuPG は寛容です。}}
例: {{ic|1=GPG_AGENT_INFO=/tmp/gpg-eFqmSC/S.gpg-agent:7795:1}}。gpg-agent を起動すると、この変数が適切に設定されます。
 
  +
{{Note|以下のステップのいくつかは、使用法によってはメールクライアントなどの外部プログラムにより提供されていることもあります。[[アプリケーション一覧/セキュリティ#暗号化, 署名, ステガノグラフィー]]も参照}}
   
  +
=== 鍵の作成 ===
{{Note|[https://www.gnupg.org/faq/whats-new-in-2.1.html GnuPG 2.1 のアナウンス] によると: GnuPG 2.1 で {{ic|GPG_AGENT_INFO}} の必要性は完全になくなり変数は無視されるようになりました。代わりに、{{ic|$GNUPGHOME/S.gpg-agent}} という決まった名前の Unix ドメインソケットが使われます。エージェントも必要に応じて、ツールがエージェントのサービスを必要としたときに起動します。}}
 
   
  +
秘密鍵を生成するにはターミナルに次を入力:
== 設定ファイル ==
 
   
  +
$ gpg --full-gen-key
デフォルトは {{ic|~/.gnupg/gpg.conf}} です。デフォルトの場所を変更したい場合は、{{ic|$ gpg --homedir ''path/to/file''}} と gpg を実行するか {{ic|$GNUPGHOME}} 変数を使って下さい。
 
   
どんな長いオプションもこのファイルに追加します。2つのダッシュを書かないで、オプションや必要な引数の名前を書いて下さい。スケルトンファイルは {{ic|/usr/share/gnupg/gpg-conf.skel}} にあります。以下はベーシックな設定ファイルです:
 
{{hc|~/.gnupg/gpg.conf|
 
default-key ''name'' # useful in case you manage several keys and want to set a default one
 
keyring ''file'' # will add ''file'' to the current list of keyrings
 
trustdb-name ''file'' # use ''file'' instead of the default trustdb
 
homedir ''dir'' # set the name of the gnupg home dir to ''dir'' instead of ~/.gnupg
 
display-charset utf-8 # bypass all translation and assume that the OS uses native UTF-8 encoding
 
keyserver ''name'' # use ''name'' as your keyserver
 
no-greeting # suppress the initial copyright message
 
armor # create ASCII armored output. Default is binary OpenPGP format
 
}}
 
   
  +
{{Tip|{{ic|--expert}} を使うことで他の暗号を利用することができます ([[wikipedia:ja:楕円曲線暗号|楕円曲線暗号]]など)}}
新規ユーザーのデフォルトオプションを設定したいときは、{{ic|/etc/skel/.gnupg/}} に設定ファイルを置いて下さい。システムに新しいユーザーが追加されたとき、ここからファイルが GnuPG のホームディレクトリにコピーされます。''addgnupghome'' というシンプルなスクリプトもあり、既存のユーザーに新しい GnuPG ホームディレクトリを作成できます:
 
   
  +
いくつか質問がきかれます。一般的に、ほとんどのユーザーは RSA (署名のみ) と RSA (暗号化のみ) の両方の鍵が必要になります。鍵長は2048ビットで十分です。4096ビットを使ったところで [https://www.gnupg.org/faq/gnupg-faq.html#no_default_of_rsa4096 "大した効果はありませんし、無駄に時間がかかるようになるだけです"] 。
# addgnupghome user1 user2
 
   
  +
副鍵の有効期限の設定は技術的には必須ではありませんが、設定することは悪くありません。標準的なユーザーなら、1年間で十分でしょう。たとえ鍵束へのアクセスを失っても、他の人が有効でないことを知ることができるようになります。鍵を作成した後、新しい鍵を再発行しなくても満了日は延長することができます。
このコマンドで {{ic|/home/user1/.gnupg}} と {{ic|/home/user2/.gnupg}} が作成されスケルトンディレクトリからファイルがコピーされます。既に GnuPG ホームディレクトリが存在するユーザーは無視されます。
 
   
  +
安全なパスフレーズを選ぶようにしてください([[セキュリティ#パスワードの管理]]を参照)。
== 基本的な鍵の管理 ==
 
   
  +
=== Backup your private key ===
{{Note|コマンドに ''{{ic|<user-id>}}'' が必要なときは、鍵 ID、指紋、名前やメールアドレスの一部などを指定できます。これについて GnuPG は寛容です。}}
 
   
  +
To backup your private key do the following:
=== 鍵の作成 ===
 
   
  +
$ gpg --export-secret-keys --armor ''<user-id>'' > privkey.asc
最初に強力なアルゴリズムを使うように設定して下さい:
 
   
  +
Place the private key in a safe place, such as a locked container or encrypted drive.
{{hc|~/.gnupg/gpg.conf|
 
personal-digest-preferences SHA512
 
cert-digest-algo SHA512
 
default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
 
personal-cipher-preferences TWOFISH CAMELLIA256 AES 3DES
 
}}
 
   
  +
{{Warning|Anyone who gains access to the above exported file will be able to encrypt and sign documents as if they were you ''without'' needing to know your passphrase.}}
GnuPG の最新版では、デフォルトのアルゴリズムとして SHA256 と AES が使われており、どちらも殆どの場合安全です。しかしながら、2.1 以前の古い GnuPG を使っている場合や、さらに高いセキュリティを求めたい場合、上記のように設定するようにしてください。
 
   
  +
=== Export your public key ===
秘密鍵を生成するにはターミナルに次を入力:
 
   
  +
In order for others to send encrypted messages to you, they need your public key.
$ gpg --full-gen-key
 
   
  +
To generate an ASCII version of your public key (e.g. to distribute it by e-mail):
{{Note|
 
* {{ic|--full-gen-key}} オプションは {{Pkg|gnupg}}-2.1.0 から使えるようになりました。
 
* {{ic|--expert}} を使うことで他の暗号を利用することができます ([[wikipedia:ja:楕円曲線暗号|楕円曲線暗号]]など)。
 
}}
 
   
  +
$ gpg --armor --output public.key --export ''<user-id>''
いくつか質問がきかれます。一般的に、ほとんどのユーザーは RSA (署名のみ) と RSA (暗号化のみ) の両方の鍵が必要になります。鍵長は2048ビットで十分です。4096ビットを使ったところで [https://www.gnupg.org/faq/gnupg-faq.html#no_default_of_rsa4096 "大した効果はありませんし、無駄に時間がかかるようになるだけです"] 。
 
   
  +
Alternatively, or in addition, you can share your key [[#Use_a_keyserver|on a keyserver]].
副鍵の有効期限の設定は技術的には必須ではありませんが、設定することは悪くありません。標準的なユーザーなら、1年間で十分でしょう。たとえ鍵束へのアクセスを失っても、他の人が有効でないことを知ることができるようになります。鍵を作成した後、新しい鍵を再発行しなくても満了日は延長することができます。
 
  +
  +
{{Tip|Add {{ic|--no-emit-version}} to avoid printing the version number, or add the corresponding setting to your configuration file.}}
  +
  +
=== Import a key ===
  +
  +
In order to encrypt messages to others, you need their public key. To import a public key to your public key ring:
  +
  +
$ gpg --import public.key
  +
  +
Alternatively, find a public key [[#Use_a_keyserver|on a keyserver]].
  +
  +
=== Use a keyserver ===
  +
  +
You can register your key with a public PGP key server, so that others can retrieve your key without having to contact you directly:
  +
  +
$ gpg --send-keys ''<key-id>''
  +
  +
To import a key from a key server:
  +
  +
$ gpg --recv-keys ''<key-id>''
  +
  +
{{Warning|Anyone can send keys to a keyserver, so you should not trust that the key you download actually belongs to the individual listed. You should verify the authenticity of the retrieved public key by comparing its fingerprint with one that the owner published on an independent source, such as their own blog or website, or contacting them by email, over the phone or in person. Using multiple authentication sources will increase the level of trust you can give to the downloaded key. See [[Wikipedia:Public key fingerprint]] for more information.}}
  +
  +
{{Tip|
  +
* An alternative key server is {{ic|pool.sks-keyservers.net}} and can be specified with {{ic|--keyserver}}; see also [[wikipedia:Key server (cryptographic)#Keyserver examples]].
  +
* You can connect to the keyserver over [[Tor]] using {{ic|--use-tor}}. {{ic|hkp://jirk5u4osbsr34t5.onion}} is the onion address for the sks-keyservers pool. [https://gnupg.org/blog/20151224-gnupg-in-november-and-december.html See this GnuPG blog post] for more information.}}
  +
  +
=== 暗号化と復号化 ===
  +
  +
暗号化や復号化をするときは複数の秘密鍵を使用することが可能です。複数の鍵を使うときは使用する鍵を選択する必要があります。{{ic|-u ''<user-id>''}} オプションや {{ic|--local-user ''<user-id>''}} オプションを使うことで選択できます。このオプションを使うとデフォルトの鍵を使用する代わりに指定された鍵を使用します。
  +
  +
ファイルを暗号化するには、次を使用:
  +
  +
$ gpg --encrypt -o secret.tar.gpg secret.tar
  +
  +
* 受取人を変更したい場合は {{ic|-r ''<user-id>''}} オプションで変更できます (または {{ic|--recipient ''<user-id>''}})。
  +
* gnupg を使えば機密文書を暗号化できますが、一度に複数のファイルを暗号化することはできません。ディレクトリやファイルシステム全体を暗号化したいときは、[[TrueCrypt]] や [[EncFS]] などを使用するか、tarball にファイルをまとめて暗号化すると良いでしょう。
  +
  +
ファイルを復号化するには、次を使用:
  +
  +
$ gpg --decrypt secret.tar.gpg
  +
  +
パスフレーズの入力が求められます。
  +
  +
== 鍵の管理 ==
   
=== 鍵の管理 ===
+
=== 鍵の編集 ===
   
 
* {{ic|gpg --edit-key ''<user-id>''}} コマンドを実行するとメニューが表示され、鍵管理に関連するほとんどの作業を行うことができます。以下は満了日を設定する例です:
 
* {{ic|gpg --edit-key ''<user-id>''}} コマンドを実行するとメニューが表示され、鍵管理に関連するほとんどの作業を行うことができます。以下は満了日を設定する例です:
168行目: 197行目:
   
 
{{Note|満了した副鍵を失効させる必要はありません、また、良い行いとは言えません。しょっちゅう鍵を無効化させているようでしたら、他人はあなたを信用しなくなるかもしれません。}}
 
{{Note|満了した副鍵を失効させる必要はありません、また、良い行いとは言えません。しょっちゅう鍵を無効化させているようでしたら、他人はあなたを信用しなくなるかもしれません。}}
 
=== 鍵のインポート ===
 
 
* 公開鍵を公開鍵束にインポート:
 
 
$ gpg --import public.key
 
 
* 秘密鍵を秘密鍵束にインポート:
 
 
$ gpg --import private.key
 
 
* キーサーバーから鍵をインポート ('--keyserver' を省略した場合、デフォルトのサーバーが使われます):
 
 
$ gpg --keyserver pgp.mit.edu --recv-keys <keyid>
 
   
 
=== 鍵を表示 ===
 
=== 鍵を表示 ===
193行目: 208行目:
 
$ gpg --list-secret-keys
 
$ gpg --list-secret-keys
   
== 暗号化と復号化 ==
+
== gpg-agent ==
   
  +
{{Deletion|Much of this is outdated and unnecessary info.|section=gpg-agent deletion}}
暗号化や復号化をするときは複数の秘密鍵を使用することが可能です。複数の鍵を使うときは使用する鍵を選択する必要があります。{{ic|-u ''<user-id>''}} オプションや {{ic|--local-user ''<user-id>''}} オプションを使うことで選択できます。このオプションを使うとデフォルトの鍵を使用する代わりに指定された鍵を使用します。
 
  +
{{Out of date|[[#GPG_AGENT_INFO]] is deprecated since {{pkg|gnupg}}-2.1. See [[#Unattended passphrase]] for new method.}}
   
ファイルを暗号化するには、次を使用:
 
 
$ gpg --encrypt -o secret.tar.gpg secret.tar
 
 
* 受取人を変更したい場合は {{ic|-r ''<user-id>''}} オプションで変更できます (または {{ic|--recipient ''<user-id>''}})。
 
* gnupg を使えば機密文書を暗号化できますが、一度に複数のファイルを暗号化することはできません。ディレクトリやファイルシステム全体を暗号化したいときは、[[TrueCrypt]] や [[EncFS]] などを使用するか、tarball にファイルをまとめて暗号化すると良いでしょう。
 
 
ファイルを復号化するには、次を使用:
 
 
$ gpg --decrypt secret.tar.gpg
 
 
パスフレーズの入力が求められます。
 
 
=== パスワードの暗号化 ===
 
 
パスワードを暗号化すれば、設定ファイルに平文で書き込まれなくなります。メールのパスワードなどが良い例でしょう。
 
 
まずパスワードを記述したファイルを作成してください。パスワードの後に空行を'''一行'''だけ追加しておく必要があります。そうしないとファイルを評価するときに gpg がエラーメッセージを返します。
 
 
そして次を実行:
 
 
$ gpg -e -a -r ''<user-id>'' ''your_password_file''
 
 
{{ic|-e}} は encrypt、{{ic|-a}} は armor (ASCII 出力)、{{ic|-r}} は受取人のユーザー ID です。
 
 
新しく {{ic|''your_password_file''.asc}} ファイルが作られます。
 
 
== gpg-agent ==
 
   
 
''gpg-agent'' はキーチェインにパスワードをリクエストしたりキャッシュしたりするのに使われるデーモンです。メールクライアントなど外部のプログラムから GnuPG を利用する場合に便利です。{{ic|gpg.conf}} に次の行を追加することで使用できます:
 
''gpg-agent'' はキーチェインにパスワードをリクエストしたりキャッシュしたりするのに使われるデーモンです。メールクライアントなど外部のプログラムから GnuPG を利用する場合に便利です。{{ic|gpg.conf}} に次の行を追加することで使用できます:
314行目: 302行目:
 
* {{ic|gpg -agent}} は標準ソケットを使いません。代わりに gnupg のホームディレクトリにある {{ic|S.gpg-agent}} という名前のソケットを使います。environment ファイルを読み込んで {{ic|/tmp}} に作成されたランダムなソケットのパスを取得するスクリプトは忘れることができます。
 
* {{ic|gpg -agent}} は標準ソケットを使いません。代わりに gnupg のホームディレクトリにある {{ic|S.gpg-agent}} という名前のソケットを使います。environment ファイルを読み込んで {{ic|/tmp}} に作成されたランダムなソケットのパスを取得するスクリプトは忘れることができます。
 
}}
 
}}
  +
* If you use SSH capabilities of gpg-agent (--enable-ssh-support), the systemd unit above will not work
   
 
{{Tip|gpg-agent が実行していること、接続を待機していることを確認するには、次のコマンドを実行してください: {{ic|$ gpg-connect-agent}}。設定が問題なければ、プロンプトが表示されます (''bye'' や ''quit'' と入力すれば接続が終了します)。}}
 
{{Tip|gpg-agent が実行していること、接続を待機していることを確認するには、次のコマンドを実行してください: {{ic|$ gpg-connect-agent}}。設定が問題なければ、プロンプトが表示されます (''bye'' や ''quit'' と入力すれば接続が終了します)。}}
340行目: 329行目:
   
 
{{Note|上流の開発者は ''gpg.conf'' で ''pinentry-mode loopback'' を設定すると他の機能が使えなくなる可能性があると示唆しています。出来るかぎりコマンドラインオプションを使うようにして下さい [https://bugs.g10code.com/gnupg/issue1772]。}}
 
{{Note|上流の開発者は ''gpg.conf'' で ''pinentry-mode loopback'' を設定すると他の機能が使えなくなる可能性があると示唆しています。出来るかぎりコマンドラインオプションを使うようにして下さい [https://bugs.g10code.com/gnupg/issue1772]。}}
 
== キーサインパーティ ==
 
 
キーサーバーやキーリングにある鍵の正当性をユーザーが確認 (つまり鍵の持ち主が本人であることを確認) できるように、PGP/GPG はいわゆる信頼の輪 ("Web of Trust") を利用しています。信頼の輪を維持するために様々なハッカーイベントが開かれており、キーサインパーティはそのひとつです。
 
 
[[Wikipedia:Zimmermann–Sassaman key-signing protocol|Zimmermann-Sassaman]] 鍵署名プロトコルはキーサインパーティを効果的に行うための方式です。[http://www.cryptnet.net/fdp/crypto/keysigning_party/en/keysigning_party.html こちら] にハウツー記事があります。
 
 
=== caff ===
 
 
キーサインパーティの後、鍵に署名したり所有者に署名を送るのを簡略化するために、''caff'' というツールを使うことができます。AUR のパッケージ {{AUR|caff-svn}} でインストールすることができ、{{AUR|signing-party-svn}} パッケージなど他の便利なツールにも付属しています。どちらにせよ、AUR から大量の依存パッケージをインストールすることになります。また、以下のように CPAN からインストールすることも可能です:
 
cpanm Any::Moose
 
cpanm GnuPG::Interface
 
 
所有者に署名を送信するには [[Wikipedia:ja:メール転送エージェント|MTA]] が必要です。MTA を設定していない場合、[[msmtp]] をインストールして下さい。
 
   
 
== スマートカード ==
 
== スマートカード ==
380行目: 355行目:
   
 
OpenSC を使わない場合は {{Ic|man scdaemon}} をチェックしてください。
 
OpenSC を使わない場合は {{Ic|man scdaemon}} をチェックしてください。
  +
  +
== Tips and tricks ==
  +
  +
=== Different algorithm ===
  +
  +
You may want to use stronger algorithms:
  +
  +
{{hc|~/.gnupg/gpg.conf|
  +
...
  +
  +
personal-digest-preferences SHA512
  +
cert-digest-algo SHA512
  +
default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
  +
personal-cipher-preferences TWOFISH CAMELLIA256 AES 3DES
  +
}}
  +
  +
In the latest version of GnuPG, the default algorithms used are SHA256 and AES, both of which are secure enough for most people. However, if you are using a version of GnuPG older than 2.1, or if you want an even higher level of security, then you should follow the above step.
  +
  +
=== Encrypt a password ===
  +
  +
It can be useful to encrypt some password, so it will not be written in clear on a configuration file. A good example is your email password.
  +
  +
First create a file with your password. You '''need''' to leave '''one''' empty line after the password, otherwise gpg will return an error message when evaluating the file.
  +
  +
Then run:
  +
  +
$ gpg -e -a -r ''<user-id>'' ''your_password_file''
  +
  +
{{ic|-e}} is for encrypt, {{ic|-a}} for armor (ASCII output), {{ic|-r}} for recipient user ID.
  +
  +
You will be left with a new {{ic|''your_password_file''.asc}} file.
  +
  +
=== Default options for new users ===
  +
  +
If you want to setup some default options for new users, put configuration files in {{ic|/etc/skel/.gnupg/}}. When the new user is added in system, files from here will be copied to its GnuPG home directory. There is also a simple script called ''addgnupghome'' which you can use to create new GnuPG home directories for existing users:
  +
  +
# addgnupghome user1 user2
  +
  +
This will add the respective {{ic|/home/user1/.gnupg}} and {{ic|/home/user2/.gnupg}} and copy the files from the skeleton directory to it. Users with existing GnuPG home directory are simply skipped.
  +
  +
=== Revoking a key ===
  +
  +
{{Warning|
  +
*Anybody having access to your revocation certificate can revoke your key, rendering it useless.
  +
*Key revocation should only be performed if your key is compromised or lost, or you forget your passphrase.}}
  +
  +
Revocation certificates are automatically generated for newly generated keys, although one can be generated manually by the user later. These are located at {{ic|~/.gnupg/openpgp-revocs.d/}}. The filename of the certificate is the fingerprint of the key it will revoke.
  +
  +
To revoke your key, simply import the revocation certificate:
  +
  +
$ gpg --import ''<fingerprint>''.rev
  +
  +
Now update the keyserver:
  +
  +
$ gpg --keyserver subkeys.pgp.net --send ''<userid>''
  +
  +
=== Change trust model ===
  +
  +
By default GnuPG uses the [[Wikipedia::Web of Trust|Web of Trust]] as the trust model. You can change this to [[Wikipedia::Trust on First|Trust on First]] Use by adding {{ic|1=--trust-model=tofu}} when adding a key or adding this option to your GnuPG configuration file. More details are in [https://lists.gnupg.org/pipermail/gnupg-devel/2015-October/030341.html this email to the GnuPG list].
  +
  +
=== Hide all recipient id's ===
  +
  +
By default the recipient's key ID is in the encrypted message. This can be removed at encryption time for a recipient by using {{ic|hidden-recipient ''<user-id>''}}. To remove it for all recipients add {{ic|throw-keyids}} to your configuration file. This helps to hide the receivers of the message and is a limited countermeasure against traffic analysis. (Using a little social engineering anyone who is able to decrypt the message can check whether one of the other recipients is the one he suspects.) On the receiving side, it may slow down the decryption process because all available secret keys must be tried (''e.g.'' with {{ic|--try-secret-key ''<user-id>''}}).
  +
  +
=== Using caff for keysigning parties ===
  +
  +
To allow users to validate keys on the keyservers and in their keyrings (i.e. make sure they are from whom they claim to be), PGP/GPG uses he [[Wikipedia::Web of Trust|Web of Trust]]. Keysigning parties allow users to get together in physical location to validate keys. The [[Wikipedia:Zimmermann–Sassaman key-signing protocol|Zimmermann-Sassaman]] key-signing protocol is a way of making these very effective. [http://www.cryptnet.net/fdp/crypto/keysigning_party/en/keysigning_party.html Here] you will find a how-to article.
  +
  +
キーサインパーティの後、鍵に署名したり所有者に署名を送るのを簡略化するために、''caff'' というツールを使うことができます。AUR のパッケージ {{AUR|caff-svn}} でインストールすることができ、{{AUR|signing-party-svn}} パッケージなど他の便利なツールにも付属しています。どちらにせよ、AUR から大量の依存パッケージをインストールすることになります。また、以下のように CPAN からインストールすることも可能です:
  +
cpanm Any::Moose
  +
cpanm GnuPG::Interface
  +
  +
To send the signatures to their owners you need a working [[Wikipedia:Message transfer agent|MTA]]. If you do not have already one, install [[msmtp]].
   
 
== トラブルシューティング ==
 
== トラブルシューティング ==
  +
  +
=== Make it work behind an http proxy ===
  +
Since 2.1.9 the http proxy option can be set like this:
  +
  +
gpg --keyserver-option http-proxy=HOST:PORT
  +
  +
See https://bugs.gnupg.org/gnupg/issue1786 for more explanation.
  +
   
 
=== Not enough random bytes available ===
 
=== Not enough random bytes available ===
418行目: 474行目:
   
 
Gnome keyring は GPG エージェントコンポーネントを実装していますが、GnuPG バージョン 2.1 から、GnuPG は {{ic|GPG_AGENT_INFO}} 環境変数を無視するようになったため、Gnome keyring を GPG エージェントとして使うことはできません。
 
Gnome keyring は GPG エージェントコンポーネントを実装していますが、GnuPG バージョン 2.1 から、GnuPG は {{ic|GPG_AGENT_INFO}} 環境変数を無視するようになったため、Gnome keyring を GPG エージェントとして使うことはできません。
  +
  +
However, since version 0.9.6 the package {{Pkg|pinentry}} provides the {{Ic|pinentry-gnome3}} program. You may set the following option in your {{Ic|gpg-agent.conf}} file
  +
pinentry-program /usr/bin/pinentry-gnome3
  +
in order to make use of that pinentry program.
  +
  +
Since version 0.9.2 all pinentry programs can be configured to optionally save a passphrase with libsecret. For example, when the user is asked for a passphrase via {{Ic|pinentry-gnome3}}, a checkbox is shown whether to save the passphrase using a password manager. Unfortunately, the package {{Pkg|pinentry}} does not have this feature enabled (see {{Bug|46059}} for the reasons). You may use {{AUR|pinentry-libsecret}} as a replacement for it, which has support for libsecret enabled.
  +
  +
=== mutt and gpg ===
  +
  +
To be asked for your GnuPG password only once per session as of GnuPG 2.1, see [https://bbs.archlinux.org/viewtopic.php?pid=1490821#p1490821 this forum thread].
   
 
=== gnupg バージョン 2.1 にアップグレードすると鍵が"消失"する ===
 
=== gnupg バージョン 2.1 にアップグレードすると鍵が"消失"する ===
449行目: 515行目:
 
== 参照 ==
 
== 参照 ==
   
* [http://gnupg.org/gph/en/manual.html GNU Privacy ハンドブック]
+
* [https://gnupg.org/ GNU Privacy Guard Homepage]
  +
* [https://fedoraproject.org/wiki/Creating_GPG_Keys Creating GPG Keys (Fedora)]
  +
* [https://wiki.debian.org/Subkeys OpenPGP subkeys in Debian]
 
* [http://blog.sanctum.geek.nz/series/linux-crypto/ A more comprehensive gpg Tutorial]
 
* [http://blog.sanctum.geek.nz/series/linux-crypto/ A more comprehensive gpg Tutorial]
* [https://www.gnupg.org/faq/gnupg-faq.html GnuPG FAQ]
 
 
* [https://help.riseup.net/en/security/message-security/openpgp/gpg-best-practices gpg.conf recommendations and best practices]
 
* [https://help.riseup.net/en/security/message-security/openpgp/gpg-best-practices gpg.conf recommendations and best practices]
 
* [https://github.com/ioerror/torbirdy/blob/master/gpg.conf Torbirdy gpg.conf]
 
* [https://github.com/ioerror/torbirdy/blob/master/gpg.conf Torbirdy gpg.conf]
  +
* [https://www.reddit.com/r/GPGpractice/ /r/GPGpractice - a subreddit to practice using GnuPG.]

2016年1月25日 (月) 02:53時点における版

公式サイト によれば:

GnuPG は RFC4880(別名 PGP)で定義される OpenPGP 標準の完全でフリーな実装です。GnuPG を使うことでデータや通信を暗号化したり署名することができます。多目的の鍵管理システムであり、あらゆる種類の公開鍵ディレクトリのアクセスモジュールです。GnuPG(またの名を GPG)は他のアプリケーションとの簡単に連携できる機能を備えたコマンドラインツールです。豊富なアプリケーションとライブラリが利用可能です。GnuPG のバージョン2は S/MIME と ssh のサポートも含んでいます。

インストール

gnupg をインストールしてください。

gnupg をインストールすると、GnuPG がパスフレーズエントリに使用するシンプルな PIN やパスフレーズエントリダイアログのコレクションである pinentry もインストールされます。pinentry はシンボリックリンク /usr/bin/pinentry によって決められ、デフォルトでは /usr/bin/pinentry-gtk-2 になります。

グラフィカルフロントエンドや GnuPG と連携するプログラムを使いたい場合はアプリケーション一覧/セキュリティ#暗号化, 署名, ステガノグラフィーを参照してください。

環境変数

GNUPGHOME

$GNUPGHOME は全ての設定ファイルを保存するディレクトリを指定するのに GnuPG によって使われます。デフォルトでは $GNUPGHOME は設定されておらず、代わりに $HOME が使われます。そのためインストール直後は ~/.gnupg ディレクトリが確認できます。スタートアップファイルに次の行を記述することでデフォルト設定を変更できます:

export GNUPGHOME="/path/to/directory"
ノート: デフォルトでは、gnupg ディレクトリのパーミッション700 に設定されており、ディレクトリのファイルのパーミッションは 600 に設定されています。ファイルの読み書きやアクセスの権限を持っているのはディレクトリの所有者だけです (r,w,x)。これはセキュリティ上の理由で設定されていることなので変更してはいけません。ディレクトリやファイルがこのセキュリティ対策に従っていない場合、ファイルやホームディレクトリのパーミッションが安全ではないという警告が表示されます。

設定ファイル

デフォルトは ~/.gnupg/gpg.conf~/.gnupg/dirmngr.conf です。デフォルトの場所を変更したい場合は、$ gpg --homedir path/to/file と gpg を実行するか $GNUPGHOME 変数を使って下さい。どんな長いオプションもこのファイルに追加します。2つのダッシュを書かないで、オプションや必要な引数の名前を書いて下さい。スケルトンファイルは /usr/share/gnupgl にあります。gpg がなんらかの操作のため最初に起動されたとき、~/.gnupg が存在しなければこれらのファイルが ~/.gnupg にコピーされます。#参照 に他の例があります。

使い方

ノート: コマンドに <user-id> が必要なときは、鍵 ID、指紋、名前やメールアドレスの一部などを指定できます。これについて GnuPG は寛容です。
ノート: 以下のステップのいくつかは、使用法によってはメールクライアントなどの外部プログラムにより提供されていることもあります。アプリケーション一覧/セキュリティ#暗号化, 署名, ステガノグラフィーも参照

鍵の作成

秘密鍵を生成するにはターミナルに次を入力:

$ gpg --full-gen-key


ヒント: --expert を使うことで他の暗号を利用することができます (楕円曲線暗号など)

いくつか質問がきかれます。一般的に、ほとんどのユーザーは RSA (署名のみ) と RSA (暗号化のみ) の両方の鍵が必要になります。鍵長は2048ビットで十分です。4096ビットを使ったところで "大した効果はありませんし、無駄に時間がかかるようになるだけです"

副鍵の有効期限の設定は技術的には必須ではありませんが、設定することは悪くありません。標準的なユーザーなら、1年間で十分でしょう。たとえ鍵束へのアクセスを失っても、他の人が有効でないことを知ることができるようになります。鍵を作成した後、新しい鍵を再発行しなくても満了日は延長することができます。

安全なパスフレーズを選ぶようにしてください(セキュリティ#パスワードの管理を参照)。

Backup your private key

To backup your private key do the following:

$ gpg --export-secret-keys --armor <user-id> > privkey.asc

Place the private key in a safe place, such as a locked container or encrypted drive.

警告: Anyone who gains access to the above exported file will be able to encrypt and sign documents as if they were you without needing to know your passphrase.

Export your public key

In order for others to send encrypted messages to you, they need your public key.

To generate an ASCII version of your public key (e.g. to distribute it by e-mail):

$ gpg --armor --output public.key --export <user-id>

Alternatively, or in addition, you can share your key on a keyserver.

ヒント: Add --no-emit-version to avoid printing the version number, or add the corresponding setting to your configuration file.

Import a key

In order to encrypt messages to others, you need their public key. To import a public key to your public key ring:

$ gpg --import public.key

Alternatively, find a public key on a keyserver.

Use a keyserver

You can register your key with a public PGP key server, so that others can retrieve your key without having to contact you directly:

$ gpg --send-keys <key-id>

To import a key from a key server:

$ gpg --recv-keys <key-id>
警告: Anyone can send keys to a keyserver, so you should not trust that the key you download actually belongs to the individual listed. You should verify the authenticity of the retrieved public key by comparing its fingerprint with one that the owner published on an independent source, such as their own blog or website, or contacting them by email, over the phone or in person. Using multiple authentication sources will increase the level of trust you can give to the downloaded key. See Wikipedia:Public key fingerprint for more information.
ヒント:

暗号化と復号化

暗号化や復号化をするときは複数の秘密鍵を使用することが可能です。複数の鍵を使うときは使用する鍵を選択する必要があります。-u <user-id> オプションや --local-user <user-id> オプションを使うことで選択できます。このオプションを使うとデフォルトの鍵を使用する代わりに指定された鍵を使用します。

ファイルを暗号化するには、次を使用:

$ gpg --encrypt -o secret.tar.gpg secret.tar
  • 受取人を変更したい場合は -r <user-id> オプションで変更できます (または --recipient <user-id>)。
  • gnupg を使えば機密文書を暗号化できますが、一度に複数のファイルを暗号化することはできません。ディレクトリやファイルシステム全体を暗号化したいときは、TrueCryptEncFS などを使用するか、tarball にファイルをまとめて暗号化すると良いでしょう。

ファイルを復号化するには、次を使用:

$ gpg --decrypt secret.tar.gpg

パスフレーズの入力が求められます。

鍵の管理

鍵の編集

  • gpg --edit-key <user-id> コマンドを実行するとメニューが表示され、鍵管理に関連するほとんどの作業を行うことができます。以下は満了日を設定する例です:
$ gpg --edit-key <user-id>
> key number
> expire yyyy-mm-dd
> save
> quit

便利なコマンド:

> passwd       # change the passphrase
> clean        # compact any user ID that is no longer usable (e.g revoked or expired)
> revkey       # revoke a key
> addkey       # add a subkey to this key
> expire       # change the key expiration time
  • 公開鍵の ASCII バージョンを生成 (例: メールなどで配るため):
$ gpg --armor --output public.key --export <user-id>
  • PGP 公開鍵サーバーに鍵を登録して、他の人があなたに直接連絡しなくても鍵を取得できるようにする:
$ gpg  --keyserver pgp.mit.edu --send-keys <key-id>
  • ユーザー Bob あてに署名と暗号化:
$ gpg -se -r Bob file
  • クリアテキスト署名を作成:
$ gpg --clearsign file

副鍵のエクスポート

複数のデバイスで同じ鍵を使い回す場合、マスター鍵を分離させて、セキュリティが低いシステムでは暗号化に必要な副鍵だけを使いたいという状況が考えられます。

まず、エクスポートしたい副鍵を確認してください:

$ gpg -K

エクスポートする副鍵だけを選択:

$ gpg -a --export-secret-subkeys [subkey id]! > /tmp/subkey.gpg
警告: If you forget to add the !, all of your subkeys will be exported.

ここで作業を終えても良いですが、パスフレーズの変更もしておくと安全です。一時フォルダに鍵をインポートします:

$ gpg --homedir /tmp/gpg --import /tmp/subkey.gpg
$ gpg --homedir /tmp/gpg --edit-key <user-id>
> passwd
> save
$ gpg --homedir /tmp/gpg -a --export-secret-subkeys [subkey id]! > /tmp/subkey.altpass.gpg
ノート: マスター鍵が存在しない、また、マスター鍵のパスワードが変更されていないという警告が表示されますが、変更したのは副鍵のパスワードなので無視してかまいません。

これで、他のデバイスで /tmp/subkey.altpass.gpg を使うことができます。

副鍵の使用

警告: 何か特段の事情がないかぎり、有効期限が切れたり無効になった副鍵を削除しないでください。削除してしまうとその副鍵で暗号化したファイルを復号化できなくなってしまいます。満了した、または無効のキーを削除するのは他のユーザーの鍵束を整理するときだけにしてください。

副鍵を設定して一定期間後に満了したら、新しい副鍵を作成できます。他のユーザーが鍵束を更新できるように数週間前に行うようにしましょう。

ノート: 新しい鍵を作成する必要はありません。期限がきて使えなくなっただけだからです。有効期間を延長することができます。
  • 新しい副鍵を作成 (署名と暗号化の鍵の両方)
$ gpg --edit-key <user-id>
> addkey

そして質問に答えて下さい (推奨される設定については前のセクションを参照)。

  • 変更を保存:
> save
  • キーサーバーにアップデート:
$ gpg  --keyserver pgp.mit.edu --send-keys <user-id>
ノート: 満了した副鍵を失効させる必要はありません、また、良い行いとは言えません。しょっちゅう鍵を無効化させているようでしたら、他人はあなたを信用しなくなるかもしれません。

鍵を表示

  • 公開鍵束の鍵:
$ gpg --list-keys
  • 秘密鍵束の鍵:
$ gpg --list-secret-keys

gpg-agent

This article or section is being considered for deletion.
Reason: Much of this is outdated and unnecessary info. (Discuss)
この記事またはセクションは情報が古くなっています。
理由: #GPG_AGENT_INFO is deprecated since gnupg-2.1. See #Unattended passphrase for new method. (Discuss)


gpg-agent はキーチェインにパスワードをリクエストしたりキャッシュしたりするのに使われるデーモンです。メールクライアントなど外部のプログラムから GnuPG を利用する場合に便利です。gpg.conf に次の行を追加することで使用できます:

~/.gnupg/gpg.conf
use-agent

この設定によって GnuPG はパスワードが必要になった時にエージェントを使うようになります。ただし、あらかじめエージェントを実行しておく必要があります。エージェントを自動的に起動するには、.xinitrc.bash_profile に以下のエントリを追加してください。$GNUPGHOME を変更していた場合は envfile のパスを忘れずに変更するようにしてください。

~/.bash_profile
envfile="$HOME/.gnupg/gpg-agent.env"
if [[ -e "$envfile" ]] && kill -0 $(grep GPG_AGENT_INFO "$envfile" | cut -d: -f 2) 2>/dev/null; then
    eval "$(cat "$envfile")"
else
    eval "$(gpg-agent --daemon --enable-ssh-support --write-env-file "$envfile")"
fi
export GPG_AGENT_INFO  # the env file does not contain the export statement
export SSH_AUTH_SOCK   # enable gpg-agent for ssh

その後、セッションを一度ログアウトしてからログインしなおして下さい。gpg-agent が有効になっているか確認:

$ pgrep gpg-agent

設定

gpg-agent は ~/.gnupg/gpg-agent.conf ファイルで設定することができます。設定オプションは man gpg-agent に記載されています。例えば、未使用の鍵の cache ttl を変更することができます:

~/.gnupg/gpg-agent.conf
default-cache-ttl 3600
ヒント: セッションを通してパスフレーズをキャッシュするには、次のコマンドを実行してください:
$ /usr/lib/gnupg/gpg-preset-passphrase --preset XXXXXX

XXXX は鍵輪に置き換えてください。鍵輪の値は gpg --with-keygrip -K を実行することで取得できます。パスフレーズは gpg-agent が再起動されるまで保存されます。default-cache-ttl の値を設定した場合、そちらが優先されます。

エージェントのリロード

設定を変更した後は、gpg-connect-agentRELOADAGENT という文字列をパイプで渡して、エージェントをリロードしてください。

$ echo RELOADAGENT | gpg-connect-agent

シェルに OK と出力されます。

pinentry

最後に、ユーザーにパスワードを尋ねる方法をエージェントに設定する必要があります。gpg-agent の設定ファイルで設定できます。

デフォルトでは gtk のダイアログが使われます。使用できるオプションは info pinentry を見て下さい。ダイアログの実装を変更するには pinentry-program 設定オプションを設定します:

~/.gnupg/gpg-agent.conf

# PIN entry program
# pinentry-program /usr/bin/pinentry-curses
# pinentry-program /usr/bin/pinentry-qt4
# pinentry-program /usr/bin/pinentry-kwallet

pinentry-program /usr/bin/pinentry-gtk-2
ヒント: /usr/bin/pinentry-kwallet を使うには kwalletcli パッケージをインストールする必要があります。

変更を行った後は、gpg-agent をリロードしてください。

systemd ユーザーで gpg-agent を起動

Systemd/ユーザー 機能を使ってエージェントを起動することが可能です。

systemd ユニットファイルを作成:

~/.config/systemd/user/gpg-agent.service
[Unit]
Description=GnuPG private key agent
IgnoreOnIsolate=true

[Service]
Type=forking
ExecStart=/usr/bin/gpg-agent --daemon --homedir=%h/.gnupg
ExecStop=/usr/bin/pkill gpg-agent
Restart=on-abort

[Install]
WantedBy=default.target
ノート:
  • GNUPGHOME など、サービスに環境変数を設定する必要があります。詳しくは systemd/ユーザー#環境変数 を見て下さい。
  • gnupg ホームディレクトリが ~/.gnupg の場合、パスを指定する必要はありません。
  • gpg -agent は標準ソケットを使いません。代わりに gnupg のホームディレクトリにある S.gpg-agent という名前のソケットを使います。environment ファイルを読み込んで /tmp に作成されたランダムなソケットのパスを取得するスクリプトは忘れることができます。
  • If you use SSH capabilities of gpg-agent (--enable-ssh-support), the systemd unit above will not work
ヒント: gpg-agent が実行していること、接続を待機していることを確認するには、次のコマンドを実行してください: $ gpg-connect-agent。設定が問題なければ、プロンプトが表示されます (byequit と入力すれば接続が終了します)。

無人のパスフレーズ

GnuPG 2.1.0 から gpg-agent と pinentry の利用が必須になりました。これによって --passphrase-fd 0 コマンドラインオプションによって STDIN からパイプで渡されたパスフレーズの後方互換性が損ねられています。古いリリースと同じような機能を使うには2つのことをする必要があります:

まず、gpg-agent の設定を編集して loopback pinentry モードを許可してください:

~/.gnupg/gpg-agent.conf
allow-loopback-pinentry

gpg-agent プロセスが実行している場合は再起動して変更を適用します。

次に、更新する必要があるアプリケーションに以下のようにコマンドラインパラメータを含めて loopback モードを使用します:

$ gpg --pinentry-mode loopback ...

もしくは、コマンドラインで設定ができない場合、オプションを設定に追加します:

~/.gnupg/gpg.conf
pinentry-mode loopback
ノート: 上流の開発者は gpg.confpinentry-mode loopback を設定すると他の機能が使えなくなる可能性があると示唆しています。出来るかぎりコマンドラインオプションを使うようにして下さい [1]

スマートカード

ノート: pcsclitelibusb-compat をインストールして、pcscd.service サービスを systemd で実行する必要があります。

GnuPG はスマートカードリーダーのインターフェイスとして scdaemon を使います。詳しくは man ページを参照してください。

GnuPG のみ設定

GnuPG ベース以外のカードを使う予定がない場合は、~/.gnupg/scdaemon.confreader-port パラメータを確認してください。'0' が最初に利用できるシリアルポートリーダーを、'32768' (デフォルト) が最初の USB リーダーを示しています。

GnuPG と OpenSC

opensc ドライバーであらゆるスマートカードを使う場合は (例: いろいろな国の ID カード)、GnuPG の設定に注意する必要があります。何も設定をしていないと gpg --card-status を使った時に以下のようなメッセージが表示されることがあります:

gpg: selecting openpgp failed: ec=6.108

デフォルトでは、scdaemon はデバイスに直接接続しようとします。リーダーが他のプロセスによって使用中だとこの接続は失敗します。例えば: OpenSC によって使用される pcscd デーモン。この状況に対処するには、opensc と同じ基盤のドライバーを使って一緒に動作できるようにする必要があります。scdaemon に pcscd を使用させるため、~/.gnupg/scdaemon.conf から reader-port を削除して、libpcsclite.so ライブラリの場所を指定し、ccid を無効化してください:

~/.gnupg/scdaemon.conf
pcsc-driver /usr/lib/libpcsclite.so
card-timeout 5
disable-ccid

OpenSC を使わない場合は man scdaemon をチェックしてください。

Tips and tricks

Different algorithm

You may want to use stronger algorithms:

~/.gnupg/gpg.conf
...

personal-digest-preferences SHA512
cert-digest-algo SHA512
default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed
personal-cipher-preferences TWOFISH CAMELLIA256 AES 3DES

In the latest version of GnuPG, the default algorithms used are SHA256 and AES, both of which are secure enough for most people. However, if you are using a version of GnuPG older than 2.1, or if you want an even higher level of security, then you should follow the above step.

Encrypt a password

It can be useful to encrypt some password, so it will not be written in clear on a configuration file. A good example is your email password.

First create a file with your password. You need to leave one empty line after the password, otherwise gpg will return an error message when evaluating the file.

Then run:

$ gpg -e -a -r <user-id> your_password_file

-e is for encrypt, -a for armor (ASCII output), -r for recipient user ID.

You will be left with a new your_password_file.asc file.

Default options for new users

If you want to setup some default options for new users, put configuration files in /etc/skel/.gnupg/. When the new user is added in system, files from here will be copied to its GnuPG home directory. There is also a simple script called addgnupghome which you can use to create new GnuPG home directories for existing users:

# addgnupghome user1 user2

This will add the respective /home/user1/.gnupg and /home/user2/.gnupg and copy the files from the skeleton directory to it. Users with existing GnuPG home directory are simply skipped.

Revoking a key

警告:
  • Anybody having access to your revocation certificate can revoke your key, rendering it useless.
  • Key revocation should only be performed if your key is compromised or lost, or you forget your passphrase.

Revocation certificates are automatically generated for newly generated keys, although one can be generated manually by the user later. These are located at ~/.gnupg/openpgp-revocs.d/. The filename of the certificate is the fingerprint of the key it will revoke.

To revoke your key, simply import the revocation certificate:

$ gpg --import <fingerprint>.rev

Now update the keyserver:

$ gpg --keyserver subkeys.pgp.net --send <userid>

Change trust model

By default GnuPG uses the Web of Trust as the trust model. You can change this to Trust on First Use by adding --trust-model=tofu when adding a key or adding this option to your GnuPG configuration file. More details are in this email to the GnuPG list.

Hide all recipient id's

By default the recipient's key ID is in the encrypted message. This can be removed at encryption time for a recipient by using hidden-recipient <user-id>. To remove it for all recipients add throw-keyids to your configuration file. This helps to hide the receivers of the message and is a limited countermeasure against traffic analysis. (Using a little social engineering anyone who is able to decrypt the message can check whether one of the other recipients is the one he suspects.) On the receiving side, it may slow down the decryption process because all available secret keys must be tried (e.g. with --try-secret-key <user-id>).

Using caff for keysigning parties

To allow users to validate keys on the keyservers and in their keyrings (i.e. make sure they are from whom they claim to be), PGP/GPG uses he Web of Trust. Keysigning parties allow users to get together in physical location to validate keys. The Zimmermann-Sassaman key-signing protocol is a way of making these very effective. Here you will find a how-to article.

キーサインパーティの後、鍵に署名したり所有者に署名を送るのを簡略化するために、caff というツールを使うことができます。AUR のパッケージ caff-svnAUR でインストールすることができ、signing-party-svnAUR パッケージなど他の便利なツールにも付属しています。どちらにせよ、AUR から大量の依存パッケージをインストールすることになります。また、以下のように CPAN からインストールすることも可能です:

cpanm Any::Moose
cpanm GnuPG::Interface

To send the signatures to their owners you need a working MTA. If you do not have already one, install msmtp.

トラブルシューティング

Make it work behind an http proxy

Since 2.1.9 the http proxy option can be set like this:

 gpg --keyserver-option http-proxy=HOST:PORT

See https://bugs.gnupg.org/gnupg/issue1786 for more explanation.


Not enough random bytes available

鍵を生成するときに、gpg は以下のエラーを表示することがあります:

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

残っているエントロピーを確認するには、カーネルパラメータをチェックしてください:

cat /proc/sys/kernel/random/entropy_avail

エントロピーがたくさんある健康的な Linux 環境ならマックスの 4,096 ビットに近い値が返されます。返ってくる値が 200 以下の場合、システムのエントロピーが足りていません。

エントロピー問題を解決するには、メッセージ通りのことをするのがベストです (例: ディスクを動かす、マウスを動かす、wiki を編集する - 何でもエントロピーの生成に繋がります)。それでも問題が解決しない場合、エントロピーを使い果たしているサービスが何なのかチェックして、しばらくそのサービスを停止してみてください。サービスを停止できない場合、乱数生成#高速な RNG を見て下さい。

su

pinentry を使う場合、使用するターミナルデバイス (例: /dev/tty1) の適切なパーミッションが必要です。しかしながら、su (または sudo) を使用すると、所有権は元のユーザーに残り、新しいユーザーにはなくなります。これでは pinentry はたとえ root であっても起動しません。pinentry を使用する (つまりエージェントで gpg を使用する) 前にデバイスのパーミッションを同じ所に変更する必要があります。root で gpg を実行する場合、gpg を使用する直前に所有者を root に変更してください:

chown root /dev/ttyN  # where N is the current tty

そして gpg を使用した後に元に戻して下さい。おそらく /dev/pts/ と同じのが正しいです。

ノート: The owner of tty must match with the user for which pinentry is running. Being part of the group tty is not enough.

エージェントがファイルの終末についてエラーを表示する

デフォルトの pinentry プログラムは pinentry-gtk-2 であり、D-Bus セッションバスを正しく実行する必要があります。詳しくは一般的なトラブルシューティング#セッションのパーミッションを見て下さい。

もしくは、pinentry-qt を使うこともできます。#pinentry を参照。

KGpg 設定のパーミッション

There have been issues with kdeutils-kgpg being able to access the ~/.gnupg/ options. One issue might be a result of a deprecated options file, see the bug report.

Another user reported that KGpg failed to start until the ~/.gnupg folder is set to drwxr-xr-x permissions. If you require this work-around, ensure that the directory contents retain -rw------- permissions! Further, report it as a bug to the developers.

gnome-keyring と gpg-agent が衝突する

Gnome keyring は GPG エージェントコンポーネントを実装していますが、GnuPG バージョン 2.1 から、GnuPG は GPG_AGENT_INFO 環境変数を無視するようになったため、Gnome keyring を GPG エージェントとして使うことはできません。

However, since version 0.9.6 the package pinentry provides the pinentry-gnome3 program. You may set the following option in your gpg-agent.conf file

 pinentry-program /usr/bin/pinentry-gnome3

in order to make use of that pinentry program.

Since version 0.9.2 all pinentry programs can be configured to optionally save a passphrase with libsecret. For example, when the user is asked for a passphrase via pinentry-gnome3, a checkbox is shown whether to save the passphrase using a password manager. Unfortunately, the package pinentry does not have this feature enabled (see FS#46059 for the reasons). You may use pinentry-libsecretAUR as a replacement for it, which has support for libsecret enabled.

mutt and gpg

To be asked for your GnuPG password only once per session as of GnuPG 2.1, see this forum thread.

gnupg バージョン 2.1 にアップグレードすると鍵が"消失"する

gpg --list-keys を実行しても以前まで使っていた鍵が表示されない場合、また、アプリケーションが鍵を見つけられないまたは鍵が不正だとエラーを吐く場合、鍵が新しいフォーマットに移行できていない可能性があります。

GnuPG invalid packet workaround を読んで下さい。要約すると、旧式の pubring.gpgsecring.gpg ファイルの鍵にはバグが存在しており、新しい pubring.kbx ファイルと private-keys-v1.d/ サブディレクトリ、そしてディレクトリのファイルによって置き換えられたということが書かれています。以下のコマンドを実行することで消失した鍵を復旧させることができるかもしれません:

$ cd
$ cp -r .gnupg gnupgOLD
$ gpg --export-ownertrust > otrust.txt
$ gpg --import .gnupg/pubring.gpg
$ gpg --import-ownertrust otrust.txt
$ gpg --list-keys

(鍵を受信しようとすると) どのキーサーバーでも gpg がフリーズする

特定のキーサーバーで鍵を受信しようとして gpg がフリーズしている場合、dirmngr を kill して (問題が起こっていない) 他のキーサーバーにアクセスできるようにする必要があります。そうしないと全てのキーサーバーでフリーズしてしまいます。

スマートカードが検出されない

スマートカードにアクセスするための権限がない場合、カードを正しく設定して接続しても、card error が表示されることがあります。

スマートカードにアクセスする必要があるユーザーに scard を追加することで解決できます。追加したら、以下のような udev ルールを作って下さい:

/etc/udev/rules.d/71-gnupg-ccid.rules
ACTION=="add", SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="1050", ENV{ID_MODEL_ID}=="0116|0111", MODE="664", GROUP="scard"

VENDOR と MODEL は lsusb の出力にあわせて変更する必要があります。上記は YubikeyNEO の例です。

参照