How to manage one only key per each git repository?

As mentioned in “ssh,github,it doesnot work”, the trick is to not use the default id_rsa(.pub) names for your public:private keys (because yo can only define one couple of those), but different names.

But that would be only if you were to access those repos as different users

In your case, you are accessing the repos with the same users, and one ssh key should be enough.

See “GitHub help”:

This error means the key you are pushing with is attached to another repository as a deploy key, and does not have access to the repository you are trying to push to.

To remedy this, remove the deploy key from the repository, and attach the key to your user account instead.


This is for using GitHub for two different users.

You then define a ~/.ssh/config file in which you reference each private keys by their full path:

Host github1
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_repo1

Host github2
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_repo2

Instead of using git@gihub.com:user/repo1, you would use:

github1:user/repo1

That uses the key Host entry ‘github1‘ to reference the user (git), hostname (github.com) and the exact private/public key to use ~/.ssh/id_repo1(.pub)


So if you have a second repo which use a second key stored as ~/.ssh/id_repo2(.pub), you need to use the entry ‘github2‘ (you can name it as you want) defined above, and then change the url you have for origin:

git remote set-url origin github2:user/repo2

That way, a git push will use the right key (the one for the repo2)

If you don’t, you will be able to push for one repo (using the default key ~/.ssh/id_rsa(.pub), default name), but you won’t be able to push to the second repo, which need a different set of public/private key.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)