0

I've recently set up an ubuntu server on an old Dell Optiplex. I can remote in via ssh when on the same network. However, when I try to ssh in from a different network using the public IP, I get the following error:

kex_exchange_identification: Connection closed by remote host

I have searched this error on this forum as well as many others and have tried many different ways to fix this error, but nothing has worked so far. I have port forwarded to the server's static IP, I've allowed OpenSSH and opened port 22 on my server through UFW, and I've set up a VPN that connects my computer to my network. None of these have worked so far.

What am I doing wrong? If anyone has any other ideas that I could try, or anything that I should quadruple check that would be fantastic. Thanks so much.

2 Answers 2

0

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

0

Sorry for having to submit an answer as I can't yet comment as I don't have enough reputation.

It seems like we need to do a little more debugging to answer this question properly but you mention UFW so I am wondering if this is actually misconfigured.

There's also a possibility that your /etc/hosts.allow and /etc/hosts.deny configs are misconfigured.

Additionally, are you using Password auth or Public Key auth? The reason I ask this is that even if you're using password auth the ssh client will still send your host-id keys during the connection phase, which the ssh server may consider as an authentication failure (in certain configurations) and means you won't get to the point where you enter your password. This can be fixed by using the following:

ssh -o PubkeyAuthentication=No -o PreferredAuthentications=Password <username>@<your server IP>

If you can submit the output from:

UFW with:

sudo ufw status

Double check the entries in your /etc/hosts.* files.

Also submit the output debug output when trying to authenticate by adding the -v flag, e.g:

ssh -v -i <ssh_privkey> <username>@<your server IP>

Hopefully we can get to the bottom of this one.

You must log in to answer this question.

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