Elena Ep
Elena Ep

Reputation: 45

cannot connect to github via ssh

I have created keys and put my public key into my github account. Then, in ~/.ssh I created the following config file:

Host github
  HostName [email protected]
  IdentityFile ~/.ssh/id_rsa2.pub

When I do ssh github

ssh: Could not resolve hostname [email protected]: nodename nor servname provided, or not known

And when I do ssh -T [email protected]

Permission denied (publickey).

What am I doing wrong? The public key I put in my github account says "Never used".

Thank you in advance

Upvotes: 1

Views: 8051

Answers (1)

evotion
evotion

Reputation: 365

The problem is, you are trying to use the public key for authentication. The private key, is e.g. id_rsa2 while the public key is id_rsa2.pub, at least per default, when generated with ssh-keygen.

As default ssh uses id_rsa for identification, so you have to use:

ssh -i ~/.ssh/id_rsa2 -T [email protected]

The ssh config should look like this:

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa2

The Host value is important, because that's what you have to use to use the configuration. You now can use ssh github.com. If you don't change the Host line, you need to use ssh github, but this could break other tools.

Alternatively you could use ssh-agent. In this case you do not need to create the config and just add the key to your ssh-agent and ssh to github.

ssh-add ~/.ssh/id_rsa2
ssh -T [email protected]

Upvotes: 4

Related Questions