Using SSH keys in GitHub (single or multiple)
Generating new SSH key
Note: make sure the generated SSH key has correct access rights:Adding PUBLIC key to Github
Make sure you upload PUBLIC key!
Single SSH key setup
Edit ~/.ssh/config
and put there the following content:
And that's it, you can clone your private repo
Multiple SSH keys setup
Modify ~/.ssh/config
Edit ~/.ssh/config
and put there the following content:
<name>
with some unique name which will identify your accounts. It might be account1
, but also f.ex. your username
Set the appropriate origin url
In the git repository:
# Check current origin URL
git config --get remote.origin.url
> https://github.com/<repo-path>.git
# Remove origin URL
git remote remove origin
# Add new, modified origin URL
git remote add origin github.com-<name>:/<repo-path>.git
<name>
with the name you put in your ~/.ssh/config
file
Set the appropriate user.name and user.email in the current repo
If you want to override your username and email in the repository, you can do it:
Note: if you struggle with remembering if you have entered correct user.name
and user.email
in each of your repos, I recommend adding this information into command prompt -
see Agnoster Theme with Git user display