1 台のデバイスで複数の Bitbucket ユーザーの SSH キーを管理する
If you have more than one Bitbucket Cloud account (such as a personal account and a work account), some additional configuration is required to use two (or more) accounts on the same device. This additional configurations ensures that Git connects to Bitbucket as the correct user for each repository cloned to your device. Due to the differences between operating systems and SSH-based access methods (Personal SSH Keys and Access Keys), this guide should be read alongside the relevant SSH setup guide for your operating system.
Check that SSH is installed and the SSH Agent is started (see the relevant SSH setup guide for your operating system).
アカウントごとに次のような SSH キー ペアを作成します。
ssh-keygen -t ed25519 -b 4096 -C "{username@emaildomain.com}" -f {ssh-key-name}次のような各非公開キーを SSH エージェントに追加します。
ssh-add ~/.ssh/{ssh-key-name}次のような各非公開キーを SSH 構成に追加します。
#bitbucket_username1 account Host bitbucket.org-bitbucket_username1 HostName bitbucket.org User git IdentityFile ~/.ssh/{ssh-key-bitbucket_username1} IdentitiesOnly yes #bitbucket_username2 account Host bitbucket.org-bitbucket_username2 HostName bitbucket.org User git IdentityFile ~/.ssh/{ssh-key-bitbucket_username2} IdentitiesOnly yesWhere
bitbucket_username1andbitbucket_username2are the Bitbucket usernames of the two accounts the SSH keys were created for. Your Bitbucket username is listed under Bitbucket profile settings on your Bitbucket Personal settings page.Add the public keys to the corresponding accounts on Bitbucket Cloud (see the relevant SSH setup guide for your operating system).
リポジトリをクローンするか、リポジトリがすでにクローンされている場合は
git remoteを更新します。リポジトリをクローンするには、更新されたホスト
bitbucket.org-{bitbucket_username}でgit cloneコマンドを使用して次のようにします。git clone git@bitbucket.org-{bitbucket_username}:{workspace}/{repo}.gitすでにクローンされているリポジトリの Git リモートを更新するには、更新されたホスト
bitbucket.org-{bitbucket_username}のリポジトリ内からgit remoteコマンドを次のように実行します。git remote set-url origin git@bitbucket.org-{bitbucket_username}:{workspace}/{repo}.git
関連するリポジトリに移動して Git 構成を次のように更新することによって、リポジトリの Git 構成を関連するユーザーに更新します。
git config user.name "{bitbucket_username}" git config user.email "{user@example.com}"git configを--globalオプションなしで実行すると、ユーザー全体ではなく、個々のリポジトリにユーザー詳細が設定されます。
この内容はお役に立ちましたか?