0

To work with Hadoop, I edited the hosts file and deletе some lines (these lines interfered with correct operation). When running ssh localhost, I encountered the error:

kex_exchange_identification: read: Connection reset by peer

Configuration:

  • hosts.allow:
    sshd : ALL
    ALL : ALL
    
  • hosts.deny:
    sshd: ALL
    
  • hosts:
    ##
    # Host Database
    #
    # localhost is used to configure the loopback interface
    # when the system is booting.  Do not change this entry.
    ##
    127.0.0.1   localhost
    255.255.255.255 broadcasthost
    ::1             localhost
    
  • ls -ld /etc /etc/ssh* /etc/ssh*/*:
    lrwxr-xr-x@  1 root  wheel      11  1 янв  2020 /etc -> private/etc
    drwxrwxr-x  13 root  wheel     416  2 окт 23:26 /etc/ssh
    -rwxrwxr-x   1 root  wheel  577388  1 янв  2020 /etc/ssh/moduli
    -rwxrwxr-x   1 root  wheel    1511  1 янв  2020 /etc/ssh/ssh_config
    -rwxrwxr-x   1 root  wheel    1405 22 ноя 18:22 /etc/ssh/ssh_host_dsa_key
    -rwxrwxr-x   1 root  wheel     620 22 ноя 18:22 /etc/ssh/ssh_host_dsa_key.pub
    -rwxrwxr-x   1 root  wheel     525 22 ноя 18:23 /etc/ssh/ssh_host_ecdsa_key
    -rwxrwxr-x   1 root  wheel     192 22 ноя 18:23 /etc/ssh/ssh_host_ecdsa_key.pub
    -rwxrwxr-x   1 root  wheel     387  2 окт 23:26 /etc/ssh/ssh_host_ed25519_key
    -rwxrwxr-x   1 root  wheel      82  2 окт 23:26 /etc/ssh/ssh_host_ed25519_key.pub
    -rwxrwxr-x   1 root  wheel    2622 22 ноя 18:22 /etc/ssh/ssh_host_rsa_key
    -rwxrwxr-x   1 root  wheel     584 22 ноя 18:22 /etc/ssh/ssh_host_rsa_key.pub
    -rwxrwxr-x   1 root  wheel    3169  1 янв  2020 /etc/ssh/sshd_config
    

How can this be fixed? I really need your help! I'm desperate :(

5
  • What's the point of ssh localhost? You are already on the system, so... why SSH?
    – Panki
    Commented Nov 22, 2021 at 22:37
  • Are you sure you only edited /etc/hosts? Perhaps you changed the permissions of files and directories in /etc? What does ls -ld /etc /etc/ssh* /etc/ssh*/* show (please add it to your question) Commented Nov 22, 2021 at 22:45
  • @roaima I add output of ls -ld /etc /etc/ssh* /etc/ssh*/* Commented Nov 22, 2021 at 23:26
  • I need to check my Mac tomorrow but those permissions look really suspect. Are you sure you didn't accidently use chmod while working as root? Commented Nov 22, 2021 at 23:46
  • @roaima No, I'm not sure. Maybe I use it. I don't remember. But how can I fix it? Now I have this eror: kex_exchange_identification: read: Connection reset by peer Connection reset by ::1 port 22 Commented Nov 23, 2021 at 0:31

1 Answer 1

1

You have broken the permissions for (at least) the files in /etc, and this is why ssh is no longer working. Here is a correct set for the files you've listed in your question:

lrwxr-xr-x@  1 root  wheel      11  1 Jan  2020 /etc -> private/etc
drwxr-xr-x  13 root  wheel     416 22 Nov 12:22 /etc/ssh
-rw-r--r--   1 root  wheel  577388  1 Jan  2020 /etc/ssh/moduli
-rw-r--r--   1 root  wheel    1511  1 Jan  2020 /etc/ssh/ssh_config
-rw-------   1 root  wheel     672 18 Jun  2018 /etc/ssh/ssh_host_dsa_key
-rw-r--r--   1 root  wheel     590 18 Jun  2018 /etc/ssh/ssh_host_dsa_key.pub
-rw-------   1 root  wheel     227 18 Jun  2018 /etc/ssh/ssh_host_ecdsa_key
-rw-r--r--   1 root  wheel     162 18 Jun  2018 /etc/ssh/ssh_host_ecdsa_key.pub
-rw-------   1 root  wheel     387 18 Jun  2018 /etc/ssh/ssh_host_ed25519_key
-rw-r--r--   1 root  wheel      82 18 Jun  2018 /etc/ssh/ssh_host_ed25519_key.pub
-rw-------   1 root  wheel    1679 18 Jun  2018 /etc/ssh/ssh_host_rsa_key
-rw-r--r--   1 root  wheel     382 18 Jun  2018 /etc/ssh/ssh_host_rsa_key.pub
-rw-r--r--   1 root  wheel    3169  1 Jan  2020 /etc/ssh/sshd_config

My suspicion is that you may have changed more permissions than these.

Unfortunately I have found conflicting and unclear documents on the correct method for correcting permissions on system files, so I would recommend you go across to https://apple.stackexchange.com/ and see whether the question on fixing permissions has previously been asked - and answered - there. (You don't need to ask specifically how to fix ssh - that will be resolved once you've fixed the permissions.)

You must log in to answer this question.

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