I installed ubuntu server 22.04.1 LTS and it is up and running. I also installed openssh-server to my Linux distro and ssh is also up and running. Now when I ssh into my linux server from a different PC on the same LAN I can successfully login and access my server. What I was trying to do is access my server remotely through the internet so I used the same method as I used for LAN ssh connection but with my public IP ssh username@myPublicIp but when I do this I get error kex_exchange_identification: Connection closed by remote host Connection closed by myPublicIp port 22. Why is this happening and what is the right way to ssh remotely through the internet to my Linux server? Thanks in advance.

EDIT: I added a port forwarding rule on my router. Port forward configuration screen shot attached below.

NOTE: I also tried setting up DMZ on my router but that didn't help either. enter image description here

  • I take it the "Host IP address" you've hidden (for no reason) is the correct IP address for the server you wish to access - if so, can you confirm your public IPv4 address is not a CG-NAT address? i.e. it's NOT in the range Commented Jan 7, 2023 at 3:28
  • @JaromandaX I think my public ip is a CG-NAT. My WAN IP on my router and my public IP defers doesn't that confirm the public IP is CG-NAT?
    – seriously
    Commented Jan 7, 2023 at 3:50
  • Perhaps the thread I opened yesterday could help: unix.stackexchange.com/questions/730757/… Commented Jan 7, 2023 at 6:38
  • @seriously yes that indicates you are behind CG-NAT. You will not be able to reach your server by accessing your public IP (the CG-NAT endpoint). Seems like you need a reverse tunnel setup, where the linux server in your LAN creates a persistent session to e.g. a cloud server.
    – Panki
    Commented Jan 7, 2023 at 13:44


You must log in to answer this question.

Browse other questions tagged .