Search code examples
gitgithubsshmacos-high-sierra

MacOS High Sierra - unable to interact with Github via ssh


I've gotten a new MacOS laptop with the latest High Sierra version.

I've generated an ssh key following Github's official guide. I've then added that to my keychain. After that I updated my ssh config file in ~/.ssh/config to be as follows:

Host *
 AddKeysToAgent yes
 UseKeychain yes
 IdentityFile ~/.ssh/id_rsa
 ForwardAgent yes

I am not prompted for a password; every single connection times out. Git pulling, testing ssh with ssh -T git@github.com, pushing upstream, etc. I have tried setting github's domain to use different ports but that didn't seem to be working. I also tried specifying a different port in the url.

Here is my usual error when trying to pull:

ssh: connect to host github.com port 22: Operation timed out
fatal: Could not read from remote repository.

I get the first line when trying to test my ssh connection, similarly with ports 443 and 1234 (the ones I've tested). I cannot disable my firewall on this machine.

I need help troubleshooting, so if anyone has any suggestions to pin down exactly why I can't interact here I'd love to hear them!


Solution

  • I've gotten a couple of e-mails asking if I had fixed the issue, so I figured I'd post my solution here.

    I suspect the reason why I couldn't connect over the ssh port was my company's firewall or my home domain not being added to the whitelist of our organization's Github.

    When I was first trying to fix the issue, I mentioned I was trying to change the port -- stupidly, I was just changing it to random port numbers to see if I got anything.

    Github supports using ssh over the https port.

    As per that documentation, running this will allow you to test the connection over https:

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

    If that is successful, you can work around this connection issue by changing your ~/.ssh/config to force ssh over the https port (443) for Github:

    Host github.com
      Hostname ssh.github.com
      Port 443
    

    For other domains, obviously, you would specify that domain-specific Host and Hostname.

    Hope this helps someone!