0

MacBook Pro 15" 2018, 32G RAM, OS 12.3

Last week I was trying to connect a PHP script to a database on my web host via SSH, and ran the following script:

<?php
  shell_exec("ssh -f -L 3307:127.0.0.1:3306 [email protected] sleep 60 >> logfile");
  $db = mysqli_connect('127.0.0.1', 'db_user', 'db_pass', 'test_ssh', 3307);
  if (!$db) {
    die("DB connection failed: " . mysqli_connect_error());
  } else {
    echo "Successfully connected!";
  }
?>

After that, I cannot SSH (or SFTP) into the web host account. Here's the verbose output:

My-MacBook-Pro:~ tech01$ ssh -vvvv -i ~/.ssh/id_rsa [email protected]
OpenSSH_8.6p1, LibreSSL 2.8.3
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug2: resolve_canonicalize: hostname 00.000.000.00 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/Users/tech01/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/Users/tech01/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: ssh_connect_direct: entering
debug1: Connecting to 00.000.000.00 [00.000.000.00] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: Connection established.
debug1: identity file /Users/tech01/.ssh/id_rsa type 0
debug1: identity file /Users/tech01/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.6
kex_exchange_identification: read: Connection reset by peer
Connection reset by 00.000.000.00 port 22
My-MacBook-Pro:~ tech01$

There was nothing in the system or WiFi logs, but this was in the launchd log:

2022-03-29 23:13:42.497859 (com.openssh.sshd) <Error>: Unknown key for plist importer (key: SHAuthorizationRight type: string)

Here's the output of: netstat -anvp tcp | awk 'NR<3 || /LISTEN/'

Proto Recv-Q Send-Q  Local Address          Foreign Address        (state)     rhiwat shiwat    pid   epid  state    options
tcp4       0      0  127.0.0.1.49179        *.*                    LISTEN      131072 131072    796      0 0x0100 0x00000002
tcp4       0      0  127.94.0.1.946         *.*                    LISTEN      131072 131072    100      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49166 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49165 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49164 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49163 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49162 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49161 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49160 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49159 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49158 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49157 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49156 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp6       0      0  fe80::aede:48ff:.49155 *.*                    LISTEN      131072 131072    104      0 0x0180 0x00000006
tcp46      0      0  *.49152                *.*                    LISTEN      131072 131072    516      0 0x0080 0x00000006
tcp4       0      0  *.22                   *.*                    LISTEN      131072 131072      1      0 0x0180 0x00000006
tcp6       0      0  *.22                   *.*                    LISTEN      131072 131072      1      0 0x0180 0x00000006

Here the output of: sudo lsof -i :22

COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
launchd   1 root    8u  IPv6 0x4914d8db57e256b7      0t0  TCP *:ssh (LISTEN)
launchd   1 root    9u  IPv4 0x4914d8e02411ce2f      0t0  TCP *:ssh (LISTEN)
launchd   1 root   11u  IPv6 0x4914d8db57e256b7      0t0  TCP *:ssh (LISTEN)
launchd   1 root   12u  IPv4 0x4914d8e02411ce2f      0t0  TCP *:ssh (LISTEN)

What I've tried:

  • Copied the RSA the keys to my old iMac running High Sierra and it connected just fine. It's not the remote server.
  • Checked the file permissions
  • Reinstalled OS 12.3
  • Disabled IPv6
  • Unloaded/reloaded the ssh.plist and rebooted SSH
  • Turning off the Mac's firewall
  • Googling the error(s) for two days
  • Killing PID 1 in Console. It restarted the laptop and didn't work.

Where exactly is the failure happening? I see a couple different lines in the verbose output that could be it, but I'm not sure so I don't know where to concentrate my efforts. My next step is re-imaging the laptop.

2 Answers 2

1

Just to clear off a few things from your list first:

  1. There's no way your PHP script had anything to do with this. It is entirely by coincidence that you ran that first and then something else happened.

  2. Your WiFi logs have nothing to do with this. The message you have found from launchd is about "sshd", not "ssh". So it doesn't have anything to do with your problem.

  3. Looking at netstat for listening sockets on your Mac has nothing to do with your problem. There's no need for that as no listening sockets on your Mac are involved in connecting to a remote server. You would not be able to diagnose anything here.

  4. Similarly for lsof. It has nothing to do with your problem, and you wouldn't be able to learn anything from its output regarding this problem.

  5. Reloading ssh.plist and restarting SSH hasn't got anything to do with your problem. Those are used for when you want to be able to connect remotely to your Mac - not when wanting to connect to a remote server from your Mac.

  6. Reinstalling the operating system, disabling IPv6, and reimaging the laptop is really not applicable here. You do not need to these things.

  7. Killing PID 1 - I have no idea where you got this idea from. It won't help you in any way - it will essentially crash your computer by stopping all programs.

Now on to your actual problem:

As far as I understand you're saying that you have key files on this computer. They have the correct permissions - and it "used to work". You're unclear about when it used to work.

You're also saying that if you copy those exact same key files to another computer with an older version of macOS - it just works.

Your output from ssh indicates that the server rejected your connection.

If it is correct that you have the right key files and the correct permissions on them - then it sounds like you have a version incompatibility problem on your hands. Basically newer versions of OpenSSH disable old and known insecure parts of the protocol - whereas old servers do not know about newer functionality. That could lead you to a situation where you cannot connect.

I would inspect the SSH log on the server and check that you are indeed running a recent version of sshd there.

It could also be that case that your server (or something between you and your server) is inspecting traffic (for security purposes) and dropping connections. For example some systems will block connections from IP-addresses that has unsuccessfully tried to connect for a specific number of times. Try again with the same computer on a different Internet connection (for example connect to a hotspot made by your phone).

-1

I had a similar problem recently on my Mac mini. Turns out if my network connection is over wi-fi I get this error. If I connect over ethernet connection, ssh works. Since you are on a Macbook I presume you are trying to ssh in over a wi-fi connection and it seems that is not possible on a Mac.

You must log in to answer this question.

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