Skip to content

Commit 6d1e479

Browse files
erichanson1Copilot
andauthored
Add SSH key management instructions for multiple accounts (#59664)
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 92db322 commit 6d1e479

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

content/account-and-profile/how-tos/account-management/managing-multiple-accounts.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,57 @@ For example, the following command sets the `GIT_SSH_COMMAND` environment variab
101101
GIT_SSH_COMMAND='ssh -i PATH/TO/KEY/FILE -o IdentitiesOnly=yes' git clone git@github.com:OWNER/REPOSITORY
102102
```
103103
104+
## Contributing to multiple accounts using SSH and multiple keys
105+
106+
If you are a member of an {% data variables.enterprise.prodname_emu_enterprise %}, but also want to collaborate outside your enterprise using a personal account, you can use different SSH keys for each account. For more information about using SSH, see [AUTOTITLE](/authentication/connecting-to-github-with-ssh).
107+
> [!WARNING]
108+
> You cannot use the same SSH key to contribute to both repositories inside your {% data variables.enterprise.prodname_emu_org %} and outside the enterprise.
109+
110+
1. Generate a different SSH key for the repositories in your {% data variables.enterprise.prodname_emu_org %}. See [AUTOTITLE](/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key). When you save the key, give it a different filename from your existing key (for instance, add -emu to the suggested name of the file).
111+
112+
1. Add the new ssh key to your {% data variables.enterprise.prodname_managed_user %}. See [AUTOTITLE](/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account#adding-a-new-ssh-key-to-your-account)
113+
114+
1. Configure your SSH Config File `~/.ssh/config` to use the different keys. For example, if your personal SSH key is `~/.ssh/id_ed25519` and your {% data variables.enterprise.prodname_emu_enterprise %} SSH key is `~/.ssh/id_ed25519-emu`
115+
116+
```text copy
117+
Host github.com
118+
IdentityFile ~/.ssh/id_ed25519
119+
IdentitiesOnly yes
120+
121+
Host github-emu.com
122+
Hostname github.com
123+
IdentityFile ~/.ssh/id_ed25519-emu
124+
IdentitiesOnly yes
125+
```
126+
127+
> [!NOTE]
128+
> The `IdentitiesOnly` line ensures that if the ssh-agent has loaded multiple keys, ssh uses the correct key when connecting.
129+
130+
1. Test your SSH configuration by running the following command to connect using the SSH key associated with your personal account - see [AUTOTITLE](/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection) for further details
131+
132+
```shell copy
133+
ssh -T git@github.com
134+
```
135+
136+
Test to see if you can connect to ({% data variables.product.github %}) using your {% data variables.enterprise.prodname_emu_enterprise %} SSH key
137+
138+
```shell copy
139+
ssh -T git@github-emu.com
140+
```
141+
142+
1. Tell `git` to use the correct key when downloading or uploading a repository in an {% data variables.enterprise.prodname_emu_org %}.
143+
To list the organizations in your {% data variables.enterprise.prodname_emu_enterprise %},
144+
{% data reusables.profile.access_org %}
145+
1. For each organization listed tell `git` to use the `github-emu.com` host.
146+
147+
For example, if one of your organizations is called `octocat-emu` then to tell `git` to use the host `github-emu.com` for repositories in the `octocat-emu` organization, run the following command
148+
149+
```shell copy
150+
git config --global url."git@github-emu.com:octocat-emu/".insteadOf "git@github.com:octocat-emu/"
151+
```
152+
153+
Now, when you clone a repository using SSH, in the `octocat-emu` organization, `git` will use the SSH key associated with your {% data variables.enterprise.prodname_emu_enterprise %} instead of your personal key.
154+
104155
## Next steps
105156
106157
For reference information, see [AUTOTITLE](/account-and-profile/reference/personal-account-reference).

0 commit comments

Comments
 (0)