I have a personal account ericpersonal and a company account ericcompanyabc (they forced me to even though they could have add my personal GitHub account to their repos) on github.com.
I'm using a computer the company gives and spend more time on work projects so I'm primarily logged in as ericcompanyabc
I then generated 2 private and public keys as a result:
❯ ls -lrt ~/.ssh
total 72
-rw------- 1 eric.nguyen eric.nguyen 110 Aug 31 11:03 authorized_keys.jcorig
-rw-r--r-- 1 eric.nguyen eric.nguyen 2004 Sep 13 14:16 known_hosts
lrwxr-xr-x 1 eric.nguyen eric.nguyen 76 Sep 25 21:53 ssh_auth_sock -> /var/folders/c3/q4dw0_q90lj6_nysk_hjt8p00000gn/T//ssh-31QAwZUf1Pmz/agent.501
-rw------- 1 eric.nguyen eric.nguyen 743 Oct 26 16:02 id_rsa2.pub
-rw------- 1 eric.nguyen eric.nguyen 3243 Oct 26 16:02 id_rsa2
-rw-r--r-- 1 eric.nguyen eric.nguyen 746 Oct 27 16:29 id_rsa1.pub
-rw------- 1 eric.nguyen eric.nguyen 3243 Oct 27 16:29 id_rsa1
-rw-r--r-- 1 eric.nguyen eric.nguyen 279 Oct 27 16:29 config
-rw------- 1 eric.nguyen eric.nguyen 225 Nov 3 17:57 authorized_keys
I have to switch between the 2 accounts using the following commands but it's very tedious:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa1
I've also tried using .ssh/config
file but no success
❯ cat ~/.ssh/config
Host githubcompany
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa1
UseKeychain yes
Host githuberic
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa2
AddKeysToAgent yes
UseKeychain yes
What can I do to make switching between Github accounts seamless?
I'm using macOS Sierra 10.12.6
su
between them with distinct prompts and environments. I wonder if shell functions could swap the variables needed -foo work
andfoo home
alias gitpersonal=eval "$(ssh-agent -s)" && ssh-add ~/.ssh/id_rsa2
would suffice