LoginSignup
5
0

More than 5 years have passed since last update.

Gitでgpgのせいでコミットに失敗したときの対処

Last updated at Posted at 2018-09-09

はじめに

Gitでコミットしようとしたところ、あまり見慣れないgpg周りでのエラーによって失敗してしまったので、対処しました。

環境

  • mac (High Sierra)
  • git 2.18.0
  • Bitbucket

VSCodeからのコミット時にエラーが発生して気がつきました。GitKrakenだと、BitBucketをOAuthで連携しているためか、問題なくコミットできます。

 エラーメッセージ

ターミナル
fatal: cannot run gpg: No such file or directory
error: gpg failed to sign the data
fatal: failed to write commit object

内容としては、この3点。

  • gpgを実行できませんでした
  • gpgがデータに署名できませんでした
  • コミットオブジェクトの書き込みに失敗しました

gpgとは

gpgは「GnuPG」ってもので、Gitでコミットなどの際に署名することで、その内容が信頼できるといったもののようです。
gpgのインストールや設定は、Bitbucketのサポートページを参考に進めていきます。

gpgをインストール

まずは、gpgをインストールしてみました。

ターミナル
$ brew install gnupg

gpgの確認

とりあえずバージョン確認

ターミナル
$ gpg --version
gpg (GnuPG) 2.2.10
libgcrypt 1.8.3
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Home: /Users/buch-mbp/.gnupg
Supported algorithms:
Pubkey: RSA, ELG, DSA, ECDH, ECDSA, EDDSA
Cipher: IDEA, 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH,
        CAMELLIA128, CAMELLIA192, CAMELLIA256
Hash: SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
Compression: Uncompressed, ZIP, ZLIB, BZIP2

gpgコマンドが使えるようになったことが確認できました。

gpgキーの生成

$ gpg --gen-key
gpg (GnuPG) 2.2.10; Copyright (C) 2018 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.

Note: Use "gpg --full-generate-key" for a full featured key generation dialog.

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

Real name: buch-mbp
Email address: example@xxx.com
You selected this USER-ID:
    "buch-mbp <example@xxx.com>"

Change (N)ame, (E)mail, or (O)kay/(Q)uit? O
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.
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.
gpg: key 1A2B3C... marked as ultimately trusted
gpg: directory '/Users/buch-mbp/.gnupg/openpgp-revocs.d' created
gpg: revocation certificate stored as '/Users/buch-mbp/.gnupg/openpgp-revocs.d/AAAAA... .rev'
public and secret key created and signed.

pub   rsa2048 2018-09-09 [SC] [expires: 2020-09-08]
      AAAAA... 
uid                      buch-mbp <example@xxx.com>
sub   rsa2048 2018-09-09 [E] [expires: 2020-09-08]

gpg: key 〜の部分に表示されたIDは、GPG Key IDでこのあと使う。

:no_entry_sign: GPG公開鍵の確認

$ gpg --armor --export 1A2B3C...
-----BEGIN PGP PUBLIC KEY BLOCK-----

...

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

:triangular_flag_on_post:GPGキーの登録画面がよくわからなかったので登録してないですが、コミット失敗は解決しました。

GPG Key IDをGitに設定

$ git config --global user.signingkey  1A2B3C...

コミットしてみる

問題なくできるようになりました。

5
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0