Original Date: 07/02/2020
layout: page
categories: [tech]
title: Configuring Multiple SSH Accounts in GitHub
tags: [git, tech]
GitHub doesn't allow to use the same ssh key with multiple accounts. If you have two keys, then you need to configure your ssh config so that it automatically chooses the right key based on the url
-
Generate keys
- ssh-keygen -t rsa_2 -b 4096 -C "some.email@gmail.com"
- enter passphrase or leave blank
- enter a filename so that it doesn’t overwrite the default file
- ssh-keygen -t rsa_2 -b 4096 -C "some.email@gmail.com"
-
Add keys to ssh-agent
- ssh-add ~/.ssh/id_rsa
- ssh-add ~/.ssh/id_rsa_2
- Verify by running: ssh-add -l
-
configure your ssh config file
Host anything.github.com HostName github.com PreferredAuthentications publickey AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa_2 IdentitiesOnly yes # * is default and applies to everything # so putting an exception for the above profile Host * !anything.github.com AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa
-
Verify your setup
| => ssh -T git@anything.github.com Hi anything! You've successfully authenticated, but GitHub does not provide shell access. 3. ________________________________________________________________________________ | => ssh -T git@github.com Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.
-
Clone a repo
- you will need to use ssh (not https)
- Replace github.com with anything.github.com
- Ex: if shown in GitHub git@github.com:barryclark/jekyll-now.git, use
- git clone git@anything.github.com:barryclark/jekyll-now.git
- you can verify this by running
- git remote show origin
- Fetch URL: git@anything.github.com:barryclark/jekyll-now.git
- git remote show origin
- you can verify this by running
- git clone git@anything.github.com:barryclark/jekyll-now.git
- Ex: if shown in GitHub git@github.com:barryclark/jekyll-now.git, use