Search This Blog

SSH access to Github from multiple accounts

  • Generate SSH Keys:
    ssh-keygen  -t rsa -b 4096 -C "email@personal.com" -f ~/.ssh/id_rsa_personal
    ssh-keygen  -t rsa -b 4096 -C "email@work.com" -f ~/.ssh/id_rsa_work
    
    The two commands above generate two key pairs: id_rsa_personal/id_rsa_personal.pub, id_rsa_work/id_rsa_work.pub
  • Add SSH Keys to your github accounts.
    • Add id_rsa_personal.pub to your personal github account:
      • Login to your github
      • Go to Settings -> Add SSH Keys
      • Copy of the content of id_rsa_personal.pub to the key field
      • Click Add Key
    • Add id_rsa_work.pub to your github account for work:
      • Login to your github
      • Go to Settings -> Add SSH Keys
      • Copy of the content of id_rsa_work.pub to the key field
      • Click Add Key
  • Create a file: ~/.ssh/config and add:
    • Host personal
         HostName github.com
         User git
         IdentityFile ~/.ssh/id_rsa_personal
      
      Host work
         HostName github.com
         User git
         IdentityFile ~/.ssh/id_rsa_work
      
  • Update stored identities:
    • ssh-add -D
      ssh-add id_rsa_personal
      ssh-add id_rsa_work
      
  • Test
    • ssh -T personal
      Hi githubPersonal! You've successfully authenticated, but GitHub does not provide shell access.
      $ ssh -T work
      Hi githubWork! You've successfully authenticated, but GitHub does not provide shell access.
      

No comments:

Post a Comment