1

I'm not able to ssh to localhost on my Mac. I found that sshd is not running in the machine (no process is running on port 22).

lsof -i:22

I found some posts asking to enable Remote Login in System Preferences -> Sharing. Eventhough it is enabled, I'm not able to ssh to localhost. The error I'm getting is this

$ssh -v localhost
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to localhost port 22.
debug1: Connection established.
debug1: identity file /Users/gkumar6/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/gkumar6/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/gkumar6/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/gkumar6/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/gkumar6/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/gkumar6/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/gkumar6/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/gkumar6/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
ssh_exchange_identification: read: Connection reset by peer

Is there anything I'm missing here?

  • It seems like your client is trying to load a bunch of keys and then failing. What does your ~/.ssh/config look like? You can either create a key (ssh-keygen) and put it in your ~/.ssh/authorized_keys or you can tweak your config to allow password login. – Bailey Parker Aug 10 '18 at 19:50
  • There is no ~/.ssh/config file in my system. How can I use it allow password login? – pkgajulapalli Aug 11 '18 at 1:03
  • If you have solved the problem, please post the solution as an answer instead of editing the question. – muru Aug 13 '18 at 2:59
  • Added the solution as answer. – pkgajulapalli Aug 13 '18 at 3:03
2

The log you are posting is showing that the secure shell daemon is running:

debug1: Connection established.

You would not see that line were it not; would instead see a more succinct log ending with Connection refused.

You are not seeing any output from lsof most likely because you are not running the command with sufficient privileges:

$ lsof -i:22
$ echo $?
1
$ sudo lsof -i:22
sudo lsof -i:22
Password:
COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
launchd   1 root   12u  IPv6 0x2feb0cecf91e551b      0t0  TCP *:ssh (LISTEN)
launchd   1 root   16u  IPv4 0x2feb0cecf91ec3a3      0t0  TCP *:ssh (LISTEN)
launchd   1 root   22u  IPv6 0x2feb0cecf91e551b      0t0  TCP *:ssh (LISTEN)
launchd   1 root   23u  IPv4 0x2feb0cecf91ec3a3      0t0  TCP *:ssh (LISTEN)

The echo statement preceding the second attempt is showing that the previous command returned an exit code of 1, indicating an error state.

  • You are correct. The sshd process is running. But do you know why I'm not able to connect to localhost via ssh? – pkgajulapalli Aug 10 '18 at 19:14
2

I've found the solution for this

I tried to run the sshd process manually listening to a different port to debug the issue.

sudo /usr/sbin/sshd -d -p 2222

It showed the actual problem.

debug1: sshd version OpenSSH_7.6, LibreSSL 2.6.2
debug1: private host key #0: ssh-rsa SHA256:oECJtUeeA3sNrAQj3phBiuWJoVl00dzLiXi20tlWF/o
debug1: private host key #1: ssh-dss SHA256:uVnKrOK+4V+y3QalyFdqDz+9eBN4oi2E3wb1MDBcgzc
debug1: private host key #2: ecdsa-sha2-nistp256 SHA256:CWapRrGUSJx2doJkDf2YR/aZy4BJ4j9K1/ZwX4eUZcg
debug1: private host key #3: ssh-ed25519 SHA256:sjzAks0Hud+Ah941pd8ZRNO6MWENdhO8wW4NMNDL2Ns
/var/empty must be owned by root and not group or world-writable.

The permissions to the directory /var/empty were

drwxr-xr-x   7 gkumar6       sys            224B Aug 12 21:02 empty

So I've changed it to sudo chown root:wheel /var/empty

drwxr-xr-x   7 root          wheel          224B Aug 12 21:02 empty

This has solved the problem for me.

1

Have you loaded sshd?

launchctl load -w /System/Library/LaunchDaemons/ssh.plist
  • Yes, but still not able to ssh to localhost – pkgajulapalli Aug 11 '18 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.