Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional SSH troubleshooting while managing multiple GitHub accounts on a Single workstation #36207

Closed
1 task done
greninja517 opened this issue Feb 7, 2025 · 5 comments
Labels
content This issue or pull request belongs to the Docs Content team ssh Content related to SSH waiting for review Issue/PR is waiting for a writer's review

Comments

@greninja517
Copy link

Code of Conduct

What article on docs.github.com is affected?

https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-your-personal-account/managing-multiple-accounts

What part(s) of the article would you like to see updated?

What is the problem?

Currently, GitHub Docs do not provide a detailed guide on configuring SSH for multiple GitHub accounts on a single workstation. Many developers face issues such as:

  • SSH key conflicts when trying to use the same SSH key for multiple accounts (error: "key already in use").
  • Inability to assign multiple SSH keys to the same host (github.com).
  • Needing to update Git remote URLs when using aliases in ~/.ssh/config.

What is the proposed solution?

I’d like to contribute a troubleshooting section that:

  • Explains why SSH conflicts happen when managing multiple GitHub accounts.
  • Shows how to configure unique host aliases in ~/.ssh/config.
  • Provides a step-by-step guide for updating Git remote URLs accordingly.

💡 Step-by-Step Guide to Fix This Issue

When managing multiple GitHub accounts on a single workstation using SSH, users may encounter authentication conflicts. Here’s how to set up SSH properly:

1️⃣ Generate Separate SSH Keys for Each Account

You cannot use the same SSH key for multiple GitHub accounts. Generate two different SSH keys:

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_github_personal
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_github_work

Add the generated public keys id_rsa_github_personal.pub and id_rsa_github_work.pub on the respective accounts.

2️⃣ Configure ~/.ssh/config with Unique Host Aliases
Since GitHub only recognizes github.com as the host, you must define aliases to specify different SSH keys:

# Personal GitHub Account
Host github-personal
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_github_personal
    User git
    IdentitiesOnly yes

# Work GitHub Account
Host github-work
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_github_work
    User git
    IdentitiesOnly yes

3️⃣ Handling Networks that Block SSH on Port 22
Some networks block SSH connections on port 22. To use GitHub’s SSH over port 443 instead, modify your config:

# Personal GitHub Account
Host github-personal
    HostName ssh.github.com
    IdentityFile ~/.ssh/id_rsa_github_personal
    User git
    Port 443
    IdentitiesOnly yes

# Work GitHub Account
Host github-work
    HostName ssh.github.com
    IdentityFile ~/.ssh/id_rsa_github_work
    User git
    Port 443
    IdentitiesOnly yes

4️⃣ Update the Git Remote URL
To ensure Git uses the correct SSH key, update the remote repository URL:

Check the Current Remote URL

git remote -v

Output:

origin  [email protected]:username/repository-name.git (fetch)
origin  [email protected]:username/repository-name.git (push)

Update the Remote URL
Change github.com to:

  • github-personal for personal repositories
  • github-work for work repositories
# For Personal Repos
git remote set-url origin git@github-personal:username/repository-name.git
# For Work Repos
git remote set-url origin git@github-work:orgname/repository-name.git

5️⃣ Test the SSH Connection
Run the following commands to verify that SSH authentication works correctly:

ssh -T github-personal
ssh -T github-work

Output:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

Why is this useful?

This guide will help developers who frequently switch between personal and work GitHub accounts. By following these troubleshooting steps, users can correctly configure SSH without running into authentication conflicts.

I’d love to contribute this section to the official GitHub Docs. Let me know if this would be valuable, and I can submit a pull request with the content. 🚀

Additional information

No response

@greninja517 greninja517 added the content This issue or pull request belongs to the Docs Content team label Feb 7, 2025
Copy link

welcome bot commented Feb 7, 2025

Thanks for opening this issue. A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines.

@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Feb 7, 2025
@isaacmbrown isaacmbrown added waiting for review Issue/PR is waiting for a writer's review ssh Content related to SSH and removed triage Do not begin working on this issue until triaged by the team labels Feb 7, 2025
@isaacmbrown
Copy link
Contributor

Hi @greninja517! Thanks for the proposal and all the details, appreciate you taking the time to outline your ideas! ✨ I've triaged this for a writer to review

@isaacmbrown
Copy link
Contributor

Hi again @greninja517 - could you expand a bit more about what problems you're aiming to address that this existing section doesn't account for? Thanks!

@greninja517
Copy link
Author

Hello, @isaacmbrown
I initially thought that there was no existing documentation addressing this issue. However, I found that the 'Contributing to multiple accounts using SSH and GIT_SSH_COMMAND' section already provides a solution using GIT_SSH_COMMAND. Since git config core.sshCommand offers a persistent and more convenient approach for managing multiple accounts, I now see that .ssh/config is not necessarily required in most cases. Given this, I believe my contribution may not add significant value beyond what’s already documented.

However, we can add the alternative option of setting up the ~/.ssh/config file in the documentation if maintainers don't find it unnecessary. Both ways provide the solution for managing the multiple accounts differently.

I would like to suggest small suggestion in that existing section. To enhance that section, we can add:

git config core.sshCommand "ssh -i ~/.ssh/private_key -o IdentitiesOnly=yes"

just below the GIT_SSH_COMMAND.
I will go ahead and close the issue if you find it neccessary for setting up the ~/.ssh/config file. Thanks !

@isaacmbrown
Copy link
Contributor

Thanks for getting back to us @greninja517! Generally we like to avoid introducing too many decision points, and aim to provide a single way of accomplishing a task where possible. I'll close this issue but we appreciate the thought and detail you provided ✨ Thanks!

@isaacmbrown isaacmbrown closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content This issue or pull request belongs to the Docs Content team ssh Content related to SSH waiting for review Issue/PR is waiting for a writer's review
Projects
None yet
Development

No branches or pull requests

2 participants