Using GPG keys

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

GPG keys are a way to sign and verify work from trusted collaborators. This page describes how to generate a GPG key to sign and verify commits and tags for use with Bitbucket Data Center and Server.

On this page:

GPG キーについて

GPG is a command line tool used together with Git to encrypt and sign commits or tags to verify contributions in Bitbucket. In order to use GPG keys with Bitbucket, you'll need generate a GPG key locally, add it to your Bitbucket account, and also set it up for use with Git. If you already have a GPG key ready to go, you can jump straight to the Add a GPG key to Bitbucket section. 

Administrators can also add GPG keys on behalf of their Bitbucket users, which can be useful if your organization manages public-key certificates with a keyserver.

GPG 鍵の要求

Project and repository administrators can enable the "Verify Commit Signature" hook to require that commits are signed with GPG keys. When this hook is enabled, only SSH access keys are allowed to push unsigned commits.

GPG のインストール

GPG がインストールされていない場合、ローカルにインストールする必要があります。GnuPG Download ページでご利用のオペレーティング システムに対応したバイナリを使用して手動で GPG をインストールすることも、Homebrew などのパッケージ マネージャーを使用することもできます。

既存の GPG キーの確認

GPG キーをすでに持っているかどうかが不明な場合、既存の GPG キーをローカルで確認できます。

既存の GPG キーを持っているかどうかの確認方法

  1. ターミナルで次のコマンドを使用して、自身がアクセス権を持つ GPG キーの一覧を表示します。

    gpg --list-secret-keys --keyid-format LONG
  2. 出力に GPG キーのペアがあるかどうかを確認します。

  3. If there are no GPG key pairs, you'll need to generate a new GPG key.

    If there are GPG key pairs you want to use, you'll need to add them to your Bitbucket account.

新しい GPG キーの生成

コミットやタグに署名するために新しい GPG キーを生成するには、GPG がインストール済みである必要があります。

新しい GPG キーの生成方法

  1. ターミナルで次のコマンドを使用して GPG キーを生成します。

    gpg --gen-key
  2.  プロンプトで確認される情報を提供します。
    1. ID 情報を入力します。
    2. セキュアなパスフレーズを入力します。

  3. 次のコマンドを使用して GPG キーの一覧を表示します。

    gpg --list-secret-keys --keyid-format LONG
  4. Copy the GPG key ID to use with Bitbucket. For example, below the GPG key ID is 7FFFC09ACAC05FD0.

    gpg --list-secret-keys --keyid-format LONG
    /Users/bitbucketbot/.gnupg/pubring.gpg
    ------------------------------
    sec rsa2048/7FFFC09ACAC05FD0 2017-06-02 [SC] [expires: 2019-06-02]
    5538B0F643277336BA7F0E457FFFC09ACAC05FD0
    uid [ultimate] BitbucketBot <bitbucket@realaddress.com>
    ssb rsa2048/95E8A289DFE77A84 2017-06-02 [E] [expires: 2019-06-02]

  5. Get your public key you'll add to Bitbucket.

    1. Paste the GPG key ID into this command to export the public key you will enter in Bitbucket.

      gpg --armor --export 7FFFC09ACAC05FD0

    2. From the output, copy your public GPG key, which starts at -----BEGIN PGP PUBLIC KEY BLOCK-----
      and ends at  -----END PGP PUBLIC KEY BLOCK-----.


You can now add your public GPG key to your Bitbucket account.


Add a GPG key

In order to use your GPG key with Bitbucket, you need to have GPG installed, and have generated a GPG key to add.

To add your GPG key to:

  1. From within Bitbucket, go to your account by clicking your profile picture in the upper-right, and select Manage account.

  2. [GPG キー] > [キーを追加] の順にクリックします。

  3. GPG キーをコピーします。

    手順について

    ターミナルで次のコマンドを使用して、GPG キーをクリップボードにコピーします。

    gpg --armor --export MY_KEY_ID | pbcopy

  4. GPG キーを [キー] フィールドにコピーして、[キーを追加] をクリックします。

GPG キーを使用するように Git を構成

In order to use GPG keys with Bitbucket, you need to configure your local version of Git which GPG key to use.

GPG キーを使用するように Git を構成する方法

  1. GPG キーの ID をコピーします。

    手順について

    GPG キーの一覧を表示するには、次のコマンドを使用します。

    gpg --list-secret-keys --keyid-format LONG


    Copy the GPG key ID to use with Bitbucket. For example, below the GPG key ID is 7FFFC09ACAC05FD0.

    gpg --list-secret-keys --keyid-format LONG
    /Users/bitbucketbot/.gnupg/pubring.gpg
    ------------------------------
    sec rsa2048/7FFFC09ACAC05FD0 2017-06-02 [SC] [expires: 2019-06-02]
    5538B0F643277336BA7F0E457FFFC09ACAC05FD0
    uid [ultimate] BitbucketBot <bitbucket@realaddress.com>
    ssb rsa2048/95E8A289DFE77A84 2017-06-02 [E] [expires: 2019-06-02]

  2. 次のコマンドに GPG キーの ID をペーストし、Git に GPG キーを設定します。

    git config --global user.signingkey MY_KEY_ID

GPG キーを使用してコミットおよびタグに署名

In order to sign commits and tags with a GPG key in Bitbucket, you need to have:

GPG キーでコミットに署名する方法

  1. When committing changes to a local branch, use the -S flag to the git commit command:

    git commit -S -m your commit message
  2. GPG キーのパスフレーズを入力します。


To sign tags with your GPG key, add the -S flag to your git tag command:

git tag -S yourtag


次のコマンドを使用して、タグが署名済みかどうかを確認できます。

git tag -v yourtag
最終更新日 2022 年 11 月 8 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.