Skip to content

Instantly share code, notes, and snippets.

@noih
Created February 20, 2024 03:13
Show Gist options
  • Save noih/31b82c8e362ffb439e8e22eec34d9e35 to your computer and use it in GitHub Desktop.
Save noih/31b82c8e362ffb439e8e22eec34d9e35 to your computer and use it in GitHub Desktop.
Multiple git accounts

SSH Config 1

~/.ssh/config

If the file does not exist, create it manually

Host account_a.gitlab.com
  Hostname gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/account_a_priv_key

Host account_b.gitlab.com
  Hostname gitlab.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/account_b_priv_key

Host account_c.github.com
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/account_c_priv_key

Change repository origin

git remote set-url origin git@account_a.gitlab.com:to/repo.git

Troubleshooting

Switch SSH key

If encountering SSH key authentication issues, try this script to re-add the key

Footnotes

  1. reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment