Git リポジトリで恒久的に認証する

このページの内容

お困りですか?

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

コミュニティに質問

Bitbucket Server では SSH に加え、管理された Git リポジトリからのプッシュとプルでの HTTP または HTTPS がサポートされています。ただし、Git は既定でユーザーの認証情報をキャッシュしないため、クローン、プッシュ、プルを実行するたびにそれらを再入力する必要があります。

このページでは、Bitbucket Server へのプッシュまたは Bitbucket Server からのプルのたびにユーザー名とパスワードを入力することを回避するために、Git リポジトリで永久的ま認証を行うための 2 つの方法を説明します。

On this page

認証情報キャッシュの使用

HTTPS 認証情報キャッシュ機能を使用するには、Git 1.7.9 以上が必要です。

Windows

 Windows では、アプリケーション git-credential-winstore を使用できます。

  1. ソフトウェアをダウンロードします
  2. 実行します。
  3. リポジトリに初めてアクセスするときに認証情報が求められ、Windows が今後の使用のために認証情報を保存します。

Linux

Linux では、Git 1.7.9 以降に同梱されている "cache" 認証ヘルパーを使用できます。Git のドキュメントには次の内容が記載されています。

This command caches credentials in memory for use by future git programs. The stored credentials never touch the disk, and are forgotten after a configurable timeout. The cache is accessible over a Unix domain socket,
restricted to the current user by filesystem permissions.

認証情報のキャッシュを有効化するには、以下のコマンドを使用します。認証情報のキャッシュを有効化すると、パスワードを入力してから 1 時間 (3600 秒) キャッシュされます。

git config --global credential.helper 'cache --timeout 3600'

"cache" 認証ヘルパーのすべての構成オプションの概要を確認するには、次のコマンドを実行します。

git help credential-cache

macOS

macOS の使用時に Git で認証情報キャッシュを使用するには、以下の手順を実行します。

  1. バイナリ git-credential-osxkeychain をダウンロードします。
  2. 次のコマンドを実行して、バイナリを実行可能にします。

    chmod a+x git-credential-osxkeychain
  3. ディレクトリ /usr/local/bin に配置します。
  4. 次のコマンドを実行します。

    git config --global credential.helper osxkeychain

.netrc ファイルの使用

The .netrc file is a mechanism that allows you to specify which credentials to use for which server. This method allows you to avoid entering a username and password every time you push to or pull from Git, but your Git password is stored in plain text.

警告

  • Git uses a utility called cURL under the covers, which respects the use of the .netrc file. Be aware that other applications that use cURL to make requests to servers defined in your .netrc file will also now be authenticated using these credentials. Also, this method of authentication is potentially unsuitable if you are accessing your Bitbucket Server instance via a proxy, as all cURL requests that target a path on that proxy server will be authenticated using your .netrc credentials.
  • cURL will not match the machine name in your .netrc if it has a username in it, so make sure you edit your .git/config file in the root of your clone of the repository and remove the user and '@' part from any clone URL's (URL fields) that look like https://user@machine.domain.com/... to make them look like http://machine.domain.com/...

Windows

  1. Create a text file called _netrc in your home directory (e.g. c:\users\kannonboy\_netrc). cURL has problems resolving your home directory if it contains spaces in its path (e.g. c:\Documents and Settings\kannonboy). However, you can update your %HOME% environment variable to point to any directory, so create your _netrc in a directory with no spaces in it (for example c:\curl-auth\) then set your %HOME% environment variable to point to the newly created directory.
  2. 以下の形式を使用して、認証情報を保存するサーバーの認証情報をファイルに追加します。

    machine stash1.mycompany.com
    login myusername 
    password mypassword
    machine stash2.mycompany.com
    login myotherusername
    password myotherpassword   

Linux または macOS

  1. Create a file called .netrc in your home directory (~/.netrc). Unfortunately, the syntax requires you to store your passwords in plain text - so make sure you modify the file permissions to make it readable only to you.
  2. 上記の「Windows」セクションの形式を使用して、認証情報を保存するサーバーの認証情報をファイルに追加します。IP アドレスかホスト名のいずれかを使用できます。Bitbucket Server を非標準ポートで実行している場合も、ポート番号を指定する必要はありません

  3. And that's it! Subsequent git clone, git pull and git push requests will now be authenticated using the credentials specified in this file.
最終更新日: 2021 年 2 月 2 日

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

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