1

I have GitHub account and I want to push local repositories into it. My key is stored at the path ~/.ssh/id_rsa_github. The path ~/.ssh/id_rsa is already used for other purpose.

I generated the key by: ssh-keygen, then saved it in the path ~/.ssh/id_rsa_github and then put it in SSH Keys tab in GitHub.

When I do: "git push -u origin master" I get the error:

The authenticity of host 'github.com (192.30.253.112)' can't be established. RSA key fingerprint is SHA256:****. Are you sure you want to continue connecting (yes/no)? Host key verification failed. fatal: Could not read from remote repository.

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

I also tried to type: ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts and then git push -u origin master and got:

Warning: Permanently added the RSA host key for IP address '192.30.253.112' to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository.

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

Can you please help me?

CrazySynthax
  • 13,662
  • 34
  • 99
  • 183
  • Try `ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts` – Slava.K Jan 17 '17 at 07:48
  • but I want to direct github to /.ssh/id_rsa_github – CrazySynthax Jan 17 '17 at 07:50
  • `id_rsa_github` and `known_hosts` files have different purposes. You need to add github to your known hosts list in order to establish connection – Slava.K Jan 17 '17 at 07:51
  • Ah, I got it - please check my answer below – Slava.K Jan 17 '17 at 07:54
  • SSH will use the key at `~/.ssh/id_rsa` by default. Since you do not want to use that, you will have to setup the host in your SSH config so it will use a different key. – poke Jan 17 '17 at 07:56
  • There are several ways to achieve this. I'd say the good answer depends on your needs. Do you have other github accounts with other keys? – chocopoche Jan 17 '17 at 07:56
  • no. ~/.ssh/id_rsa is a key for bitbucket. – CrazySynthax Jan 17 '17 at 07:58
  • @CrazySynthax There is nothing wrong with using the same key for multiple hosts. In fact, people on Linux very often already have an RSA key set up for other purposes, so they don’t even create a new one for Git. – poke Jan 17 '17 at 08:07

1 Answers1

0

Try to specify in your ssh config that you would like to use another public key for github instead of default id_rsa one:

# ~/.ssh/config
Host github-server
Hostname github.com
IdentityFile ~/.ssh/id_rsa_github
IdentitiesOnly yes

The link to repository should also be updated: git remote set-url origin git@github-server:username/repo.git

Slava.K
  • 3,073
  • 3
  • 17
  • 28