How to set up SSH and Github for multiple authenticated accounts
From blinkenwiki
This page was my guide: https://gist.github.com/oanhnn/80a89405ab9023894df7
This page provided a refresher: Adding a new SSH key to your GitHub account
And this page: Adding a new SSH key to your GitHub account
This page helped with the git
command-line stuff: https://www.atlassian.com/git/tutorials/git-forks-and-upstreams
Local Setup
My primary SSH key was already generated and store in my .ssh
directory.
- I generated a new SSH key to associate with the Delligatti Associates account:
$ ssh-keygen -t rsa -b 4096 -C "jthompson@delligattiassociates.com"
- Part of generating the key is specify where it will be stored. I specified the name da_private_key and two files are generated:
da_private_key da_private_key.pub
- This isn't necessary for using git, but will add the new key to my macOS keychain:
$ ssh-add da_private_key
On Github.com
- I followed this procedure for adding the new key to the Delligatti Associates Github account: Adding a new SSH key to your GitHub account
- Github noted the new SSH key...
- ...and sent an email to
jthompson@delligattiassociates.com
, which was the name associated with the key:
Finishing local setup
- Next I edited
~/.ssh/config
to add clauses for both the default github accound and the DA account. Note the difference between theHost
and theHostname
definitions:
# Default github account: jimthompson Host github.com HostName github.com IdentityFile ~/.ssh/id_rsa IdentitiesOnly yes # Other github account: da (delligattiassociates) Host github-da HostName github.com IdentityFile ~/.ssh/da_private_key IdentitiesOnly yes
- I tested access to github-da:
$ ssh -T git@github-da
- And I tested access to github.com to make sure it hadn't broken:
$ ssh -T git@github.com
Testing a push
- On the Github page for the Remailer repository, https://github.com/delligattiassociates/remailer, I copied the git ID for access to the repository, which is
git@github.com:delligattiassociates/remailer.git
. To ensure that the correct key is used, the hostname github.com is changed to the host alias defined in the SSH config: da-github, producing:
git@github-da:delligattiassociates/remailer.git
- I added this as a new remote for my local copy of the remailer repository:
$ git remote add da git@github-da:delligattiassociates/remailer.git
- I verified that the new remote was added for the local repository:
$ git remote -v da git@github-da:delligattiassociates/remailer.git (fetch) da git@github-da:delligattiassociates/remailer.git (push) origin git@github.com:jim-thompson/remailer.git (fetch) origin git@github.com:jim-thompson/remailer.git (push)
- Finally, I tested by pushing recent changes to the Delligatti Associates Github remailer repository:
$ git push da Enumerating objects: 26, done. Counting objects: 100% (26/26), done. Delta compression using up to 20 threads Compressing objects: 100% (22/22), done. Writing objects: 100% (22/22), 7.34 KiB | 7.34 MiB/s, done. Total 22 (delta 14), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (14/14), completed with 3 local objects. To github-da:delligattiassociates/remailer.git c771e4c..0d0550f main -> main
Note
- To make da the default upstream:
$ git push --set-upstream da main
- Now commands like git status or git push will use da as the default upstream:
$ git status On branch main Your branch is up to date with 'da/main'. nothing to commit, working tree clean
- Here's how to clone the remailer (it's a private remailer, so the authentication matters even in the clone):
$ git clone git@github-da:delligattiassociates/remailer.git