Why doesn't my SSH key work for connecting to github?
The GitHub ssh setup mentions testing your GitHub connection with:
$ ssh -T [email protected]
That follow the ssh uri syntax (also illustrated in "this answer").
But you did:
ssh github.com
(without any user). In that case, ssh reverts to the SCP syntax, which relies on a ~/.ssh/config
file, with a section "github.com
", to list:
- the user
- the hostname
- (and optionally the public key location, but by default it will try
~/.ssh/id_rsa.pub
)
To change it to a regular SSH URL, don't edit directly your .git/config file, as shown below.
Use the command git remote set-url
:
git remote set-url origin [email protected]:username/repo.git
I had a similar problem, github did not use my SSH key. I always had to enter my username and password.
I've been looking at .git/config, under [remote "origin"] there was:
url = http://github.com/path/to/repository
or
url = https://github.com/path/to/repository
I changed the line into
url = ssh://[email protected]/path/to/repository
and then it worked.
After creating a config file (~/.ssh/config
) it worked. This is what I had to put in it:
Host github.com
User git
Port 22
Hostname github.com
IdentityFile ~/.ssh/id_rsa
TCPKeepAlive yes
IdentitiesOnly yes
Thanks to @VonC for leading me to there in the comments.
I don't get why I never needed this before though.