29

So I followed the guide on how to add a SSH key to GitHub, and added a new SSH key with a passphrase to GitHub and the SSH agent. Now, if I run ssh -T git@github.com as described in the guide to test if I set everything up correctly, it doesn't even prompt me for my passphrase, but immediately returns ssh: connect to host github.com port 22: Connection refused. I have both openssh-server and openssh-client installed and the SSH service is running.

the error

Help would be appreciated.

UPDATE: When I try and clone a repository which for which I have write access from a friend's GitLab instance, it throws the same error. Seems like this is a problem with SSH, not with the keys. (I have them added to the instance.)

jona
  • 393

2 Answers2

48

Have you tried using port 443, and adding ssh. subdomain prefix?

This command will test it. You should get an error since a shell is not supported.

ssh -T -p 443 git@ssh.github.com

Then you can use a full URL to specify the project path, see Stack Overflow answer for details:

ssh://git@ssh.github.com:443/yourname/reponame.git

Recommended ~/.ssh/config setup as suggested in the comments:

# GitHub Account
Host github.com
HostName ssh.github.com
Port 443
PreferredAuthentications publickey
IdentityFile <path to your private ssh key>
Artur Meinild
  • 31,035
15

If you get a connection refused, it means you actually got a packet back which states that your destination does not accept your connection. This could mean a few things:

  1. github.com is down (not too likely, but you could always check their status on https://status.github.com/)

  2. you have an invalid IP address for github.com (manual entry in /etc/hosts or your resolver) which blocks ssh from at least your IP address

  3. you have a firewall along the way to github.com which blocks the ssh traffic (eg. local firewall or corporate firewall)