26

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 [email protected] 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.)

8

2 Answers 2

44

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 [email protected]

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

ssh://[email protected]: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>
3
  • This helps to confirm that at least the connection to github can be made. $ ssh -T -p 443 [email protected] The authenticity of host '[ssh.github.com]:443 ([192.30.253.123]:443)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '[ssh.github.com]:443,[192.30.253.123]:443' (RSA) to the list of known hosts. Hi xcaliber! You've successfully authenticated, but GitHub does not provide shell access. Commented May 30, 2018 at 3:12
  • 5
    Thank you! This worked for me and made me realize that I also had to add this to my ssh config file # GitHub Account Host github.com HostName **ssh.github.com** Port **443** PreferredAuthentications publickey IdentityFile <path to your private ssh key> *note the HostName and Port Commented Nov 5, 2018 at 17:09
  • ta behind corporate firewall this helped alot
    – aqm
    Commented Mar 20, 2019 at 15:32
13

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .