4

I registered a personal SSH key months ago and everything worked fine. Now I'm working for a company. They created their own GitHub account and I have started a new repository.

I know I have to add another SSH key, which I did.

This is the content of the ~/.ssh/config file.

Host github.com
    HostName github.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa

Host github-companyname
    HostName github.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_companyname

I also did ssh <keyname> and I am authenticated.

After that I executed the following commands.

git init
git add 
git remote add origin <repo>

It works all fine, until I run git push -u origin master.

I get this error.

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

I don't understand. Everything seems to be set up correctly.

Why am I getting that error message?

If that makes any difference, I am using OSX Sierra 10.12.4.

5
  • It seems that you have an issue with multiple ssh keys for the same host with git. I have faced a similar issue. Maybe this is of help gist.github.com/jexchan/2351996 especially the comments. Make sure in your .git/config you modify your remote origin url and change the hostname from github.com to github-companyname as defined in your ssh config. Commented Apr 28, 2017 at 5:53
  • did you add your ssh key which you use for your company github acc in the github account ssh keys section? Commented Apr 28, 2017 at 6:37
  • @IndrekOts Your link was really helpful and it solved my problem. I thank you a lot ! I will edit my answer to help other people :) Commented Apr 28, 2017 at 7:29
  • Do not add answers to the question. There is field for answer bellow! Or @IndrekOts, can you fill the answer with what you wrote in the comment, since it resolved the OPs problem? Commented Apr 28, 2017 at 20:42
  • 1
    @Jakuje added my comment as an answer. Commented Apr 29, 2017 at 7:19

1 Answer 1

6

Since my comment resolved OPs issue, I'm writing this as an answer.

The problem seems to be in the fact that you have multiple ssh keys for the same host. In your .ssh/config you have configured 2 hosts - github.com and github-companyname. In your company repository, you need to change the remote url in .git/config from [email protected]:... to git@github-companyname:.... Then ssh will use the correct key and you should have no problems with authentication.

For further reading:

When you need to clone an existing repository with your company key, you can apply the same approach.

git clone git@github-companyname:companyname/repositoryname.git

Notice that instead of github.com, the command uses github-companyname.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.