Train
Train

Reputation: 575

Mac: SSH doesn't work anymore without changing something

After searching the web for one day without a good solution I'm here to tell you my problem.

Three days ago I set up a SSH-key to use git with SSH. Everything worked fine and I was able to push and pull everything to GitHub. Since yesterday I'm not able to do it anymore. I always get the same error (shown below). SSH-key is part of the ssh-agent, config-files weren't changed and even a normal connection through SSH to GitHub is not possible. Tried it with other projects and other repos as well and got the same error. I didn't update Sierra or something else in the last days, so this can't be the reason as well.

Terminal in- and output:

User-MBP:data-analysis user$ git push -v origin master
Pushing to [email protected]:Username/data-analysis.git
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Normal SSH-connection:

User-MBP:data-analysis user$ ssh -v [email protected]
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/user/.ssh/config
debug1: /Users/user/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.113] port 443.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
ssh_exchange_identification: Connection closed by remote host

Thank you for your help!

UPDATE

Changed port back to 22 to get the following:

User-MBP:data-analysis user$ git push origin master
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

and

User-MBP:data-analysis user$ ssh -v [email protected]
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/user/.ssh/config
debug1: /Users/user/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: connect to address 192.30.253.113 port 22: Connection refused
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: connect to address 192.30.253.112 port 22: Connection refused
ssh: connect to host github.com port 22: Connection refused

Upvotes: 1

Views: 8254

Answers (3)

Train
Train

Reputation: 575

For all searching for a solution: I did the following several times and then it worked:

User-MacBook-Pro:~ user$ ssh [email protected]
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is  <fingerprint>.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
PTY allocation request failed on channel 0
Hi <username>! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

Now git and ssh work again. Don't know why this solution didn't work before.

Anyway thanks for all responses.

Upvotes: 0

Kenster
Kenster

Reputation: 25390

debug1: Connecting to github.com [192.30.253.113] port 443.
...
ssh_exchange_identification: Connection closed by remote host

"ssh_exchange_identification: Connection closed by remote host" means the remote server is deliberately closing the TCP connection immediately after accepting it. No key exchange or authentication attempt has taken place yet.

You're connecting to port 443 (HTTPS) instead of port 22 (SSH). I get the same error when I try it:

$ ssh -p 443 [email protected]
ssh_exchange_identification: Connection closed by remote host
$ ssh  [email protected]
Permission denied (publickey).

Connecting to port 443 produces the same error that you get. Connecting to the proper ssh port at least makes an attempt to authenticate (which fails because I'm not set up on github).

Apparently github doesn't accept ssh connections on port 443. Connect to port 22 instead.

Edit:

ssh: connect to host github.com port 22: Connection refused

"Connection refused" means that you're not making a TCP connection to the remote server. In this case my guess is that it's due to a firewall within your local network, blocking outgoing SSH connections. That might be why you were using port 443 for SSH in the first place.

As noted by @phd, github supports ssh to port 443, but you have to arrange to connect to "ssh.github.com" instead of just "github.com". Refer to github's documentation.

Alternately, you could speak to your local network administrators about permitting ssh access to github.

Upvotes: 3

VonC
VonC

Reputation: 1324148

You must first make sure ssh -v [email protected] is working, meaning the ssh connection test ends with:

Hi username! You've successfully authenticated, 
but GitHub does not provide shell access.

Make sure your /Users/user/.ssh/id_rsa.pub public ssh key is registered in your ssh setting profile.
Double-check if you have a /Users/user/.ssh/config file which might interfere.
For instance, this issue mentions:

I encountered the same issue and found that I had a settings in ~/.ssh/config that were used for ALL connections. I was behind a proxy and required something like the following for all outbound connections. Completely forgot this would also be applied to local connections e.g;

Host *
    ProxyCommand ...
    ServerAliveInterval 10

This setting was attempting to make all connections run through the proxy - which is incorrect for local connections

Upvotes: 1

Related Questions