kex_exchange_identification: Connection closed by remote host
Asked Answered
S

6

18

I've wanted to connect my share hosting with ssh. So I generate an ssh key in the ssh action of cpanel and authorized it. Then I've downloaded the private key and drop it in the ./ssh folder of my MacBook.I've used this code to connect my host.

ssh -p 2083  username@host IP

but I got this error:

kex_exchange_identification: Connection closed by remote host

How can I solve my problem?

Stickinthemud answered 8/4, 2021 at 9:2 Comment(1)
There can be many causes. One possibility is that the VM is shut down, which can easily happen in AWS or Azure if you have auto shutdown enabled.Coimbatore
B
14

I run into a similar case with a small computer I have in my desk. What I did to debug the issue was to run sshd -t, which runs the sshd daemon in debug mode. This command reported that the permissions of my keys were invalid. All I had to do then was to go in the folder where the keys are stored and issue chmod 0600 <your_ssh_keys>. Maybe the action you run generated things with the wrong permissions too.

Buccaneer answered 5/5, 2021 at 6:58 Comment(1)
chmod 400 authorized_keysMauri
E
5

I got this error when using docker command with remote host

docker -H ssh://user@server compose up

after some digging i found on my remote server in auth logs (/var/log/auth.log) this:

Aug  8 14:51:46 user sshd[1341]: error: beginning MaxStartups throttling
Aug  8 14:51:46 user sshd[1341]: drop connection #10 from [some_ip]:32992 on [some_ip]:22 past MaxStartups

This lead me to change MaxStartups settings in /etc/ssh/sshd_config. After restarting ssh service everything worked like a charm.

Exhalation answered 9/8, 2022 at 13:17 Comment(1)
I am also facing the issue with docker. What value you gave to MaxStartups?Nassir
H
1

I had same problem and it was happend as I use ProxyCommand in ssh config file. In my case the Host was not defined correctly which then caused the same error!

Hebetude answered 13/12, 2022 at 12:39 Comment(0)
S
1

first, make sure if the hostname is correct. A typo either in the cmd or configfile gives this error.

then, check the sshd log in the host, to find the issues.

Stoss answered 1/8, 2023 at 3:20 Comment(0)
A
1

Not so sure if my solution is working for yours. For me, I plan to connect to github via ssh. The same error occurs. I find the solution in https://github.com/orgs/community/discussions/55269 My config file content is as below.

#Windows
ProxyCommand "C:\APP\Git\mingw64\bin\connect" -S 127.0.0.1:51837 -a none %h %p

#MacOS
#ProxyCommand nc -v -x 127.0.0.1:51837 %h %p

Host github.com
  User git
  Port 443
  Hostname ssh.github.com
  # change the path here
  IdentityFile "C:\Users\Your_User_Name\.ssh\id_rsa"
  TCPKeepAlive yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  # change the path here
  IdentityFile "C:\Users\Your_User_Name\.ssh\id_rsa"
  TCPKeepAlive yes
Abram answered 4/11, 2023 at 16:1 Comment(0)
A
1

In my case the host was also the reason - I used gitea as git server and the .ssh folder and all certs in it required to be not accessible for everyone.

This makes totally sense, but I wished that the error message would give a better hint!

Ardatharde answered 19/11, 2023 at 14:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.