0

I am working in an aws ssh terminal. I kept getting permission denied to write to a lot of files and it was bugging me. I tried to execute this command in the root directory, on vscode remote:

chmod -R o+rw .

It ran the command for a lot of files in the log. Then after a bit it stopped responding. I tried logging back in, but it gave me this error:

kex_exchange_identification: Connection closed by remote host
Connection closed by (host ip address) port 22

one of my remote coworkers seems to have access, but me and my in house coworker (working off of the same user) cannot connect. We have tried connection to other users on the terminal but the response.

  • 1
    `chmod -R` anything on the root dir will indeed break the installation. Among hundreds of other problems, SSH will refuse to use key files with insecure permissions. My suggestion is restoring the permissions from the previous backup. – that other guy Jan 13 '21 at 18:34

1 Answers1

2

First of all sorry that you got locked out, Make sure your friend doesn't log out of the machine.

From the error message

kex_exchange_identification: Connection closed by remote host

It happens when private keys (files) are readable by all, i.e. have the wrong permissions.

which you did via command

chmod -R o+rw .

so below files in /etc/ssh/ usually needs to have 600 permissions

ssh_host_key
ssh_host_dsa_key
ssh_host_rsa_key

In addition to this, there might be a problem with your authorized_keys file as well

chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys
restorecon -R -v /root/.ssh

In this question adding-a-public-key-to-ssh-authorized-keys-does-not-log-me-in-automatically there are whole bunch of options you can try.

If nothing works, launch another EC2 instance and mount this problematic instance as another volume on the newly launched machine, at least you'll be able to get your code/data.

samtoddler
  • 8,463
  • 2
  • 26
  • 21