GitHubでコミットにVerifiedバッジをつけたい

Contents
  1. はじめに
  2. 準備する
  3. GPG鍵を作る
  4. GitHubに登録する
  5. Gitに登録する
  6. Mac用の設定をする
  7. できた

はじめに

GitHub のコミットに署名すると Verified というバッジが表示されます。

基本的に GitHub に書いてあるとおりにやってます。 https://help.github.com/categories/gpg/

Mac の El Capitan でやってみました。

準備する

必要なものをインストール

brew install gnupg2 gpg-agent pinentry-mac

GPG鍵を作る

鍵を作る。最後にパスフレーズを入力する。

$ gpg --gen-key
gpg (GnuPG) 2.0.30; Copyright (C) 2015 Free Software Foundation, Inc.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

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? 1
RSA keys may be between 1024 and 4096 bits long.
What keysize do you want? (2048) 4096
Requested keysize is 4096 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)
Key does not expire at all
Is this correct? (y/N) y

GnuPG needs to construct a user ID to identify your key.

Real name: onamae
Email address: onamae@example.com
Comment: for GitHub
You selected this USER-ID:
    "onamae (for GitHub) <onamae@example.com>"

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

鍵がどこにあるかは次のコマンドで確認できる。

$ gpg --list-keys --keyid-format LONG
/Users/hubot/.gnupg/secring.gpg
------------------------------------
pub   4096R/3AA5C34371567BD2 2016-03-10 [expires: 2017-03-10]
uid                          Hubot 
sub   4096R/42B317FD4BA89E7A 2016-03-10

この pub のとこの 3AA5C34371567BD2 ってのが GPG 鍵の ID。

GitHubに登録する

GitHub に GPG 鍵を登録する。

次のコマンドで公開鍵をエクスポートできるので、コピペして GitHubに登録 する。

gpg --armor --export 3AA5C34371567BD2

Gitに登録する

Git に署名用として作った GPG 鍵を登録する。

git config --global user.signingkey 3AA5C34371567BD2

次のコマンドで、自動でコミットに署名するようになる。

git config --global commit.gpgSign true

push.gpgSign ですべての push に署名するのもあった。

Mac用の設定をする

パスフレーズを KeyChain とよろしくやってくれる感じっぽい。

.gnupg/gpg.conf の user-agent のコメントを外す。

.gnupg/gpg-agent.conf というファイルを次の内容で作る。

.gnupg/gpg-agent.conf
use-standard-socket
pinentry-program /usr/local/bin/pinentry-mac

できた

こんな感じ

スクリーンショット 2016-10-08 21.17.15.png (94.5 kB)