1 台のデバイスで複数のリポジトリ アクセス キーを管理する
SSH 経由で複数の Bitbucket Cloud リポジトリにアクセスする必要があるツールやスクリプトがある場合に、デバイスに複製された各リポジトリの正しい SSH キーによって Git が Bitbucket に接続するためには、いくつかの追加設定が必要です。
読み取り専用のリポジトリ アクセス キーを使用して複数のリポジトリにアクセスするようにデバイスを設定するには、次の手順に従います。
SSH がインストールされていることをご確認ください (お使いのオペレーティング システムに関連する SSH セットアップ ガイドをご参照ください)。
~/.ssh/ディレクトリ内のリポジトリごとに次のような SSH キー ペアを作成します。cd ~/.ssh/ ssh-keygen -t ed25519 -b 4096 -C "{username@emaildomain.com}" -f {ssh-key-name}公開キーを Bitbucket Cloud の対応するリポジトリに追加します (お使いのオペレーティング システムに関連する SSH セットアップ ガイドをご参照ください)。
Create or update each repository’s
.gitconfig(not the user’s global Git configuration at~/.gitconfig) to include thecore.sshCommandsetting, with ansshcommand that uses the private key for the repository, such as:~/repository1/.gitconfig[core] sshCommand = ssh -i ~/.ssh/repository1_private_ssh-key-name~/repository2/.gitconfig[core] sshCommand = ssh -i ~/.ssh/repository2_private_ssh-key-nameユーザーのグローバル Git 構成ファイル
~/.gitconfigを更新して、includeIf設定を使用してリポジトリの Git 構成ファイルを条件付きで含めます。例:[includeIf "gitdir:~/repository1/"] path = ~/repository1/.gitconfig [includeIf "gitdir:~/repository2/"] path = ~/repository2/.gitconfig
この内容はお役に立ちましたか?