Generate new ssh key pair
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Give it a different name than default, e.g.
id_rsa_iam
.Add this key to the ssh agent,
cd ~/.ssh
andssh-add id_rsa_iam
If you get the error 'Could not open a connection to your authentication agent.' then start the ssh-agent with
eval `ssh-agent -s` ssh-add
Modify the ssh config:
touch config
(still in~/.ssh
) and put this into it:Host github.com HostName github.com User git IdentityFile ~/.ssh/id_rsa # Github when impersonating Iam Host iam.github.com # can be anything, e.g. github-iam HostName github.com User git IdentityFile ~/.ssh/id_rsa_iam
Add the public key to your GitHub account as usual.
Clone a repo using the new host:
git clone [email protected]:iam/repohere.git
Go into the repo directory and set new user name and email:
git config user.name "Iam Here" git config user.email "[email protected]"
This manual was adapted from StackOverflow.