Friday, 8 September 2017

Multiple SSH Keys settings for different github accounts

Say you have two keys. Add these two keys as following to ssh agent running on your local machine:

 $ ssh-add ~/.ssh/id_rsa_hacker
 $ ssh-add ~/.ssh/id_rsa_exchan

You can check your saved keys

 $ ssh-add -l

Sample ssh config settings, uses aliases in first line of blocks

 Host github-hacker
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_hacker

 Host github-exchan
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_exchan

then use normal flow to push your code

git clone git@github.com:hacker/myrepo.git

set remote host from the default (github.com) to match alias in the ssh config

git remote set-url origin git@github-hacker:hacker/myrepo.git
you can see the change in .git/config file if you look carefully
git add .
git commit -m "your comments" git push

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...