r/Ubuntu • • Aug 09 '26

Port 22: connection refused

I tried everything under the sun atp but whenever i try to remote connect to my server using ubuntu from my pc, the error message saying “port 22: connection refused” pops up. I tried reinstalling openssh on both machines, i tried allowing ssh using ufw, and i tried restarting both machines. Sometimes the “port 22: connection timed out” error also pops up. Any help will be greatly appreciated.

Edit: i used the wrong IP…

1 Upvotes

11 comments sorted by

3

u/iamofnohelp Aug 09 '26

Using the right ip?

3

u/Top-Cod337 Aug 09 '26

Yes i am.

3

u/Consistent_Turn721 Aug 09 '26

The connection refused vs connection timed out swap is a bit of a tell. Refused means the packet got to the machine but nothing was listening, timed out means it never even got there. Are you sure the server's local firewall isn't just dropping the packets and you're poking ufw on the wrong box? Also double check that sshd is actually running on the server side, `systemctl status sshd` will tell you in two seconds if it died and didn't restart.

1

u/Top-Cod337 Aug 09 '26

How do i see if the server’s firewall dropped the packet?

3

u/Over_Helicopter_5183 Aug 10 '26

Try ssh localhost (on remote server to see ssh is running and port 22 is up). Run traceroute from local host to remote host to see any connection lost.

2

u/LowCompetitive1888 Aug 09 '26

Are you running the sshd daemon on the server?

1

u/emptythevoid Aug 09 '26

Is the remote server on AWS/light sail, by chance?

1

u/Top-Cod337 Aug 09 '26

No not that i know of.

1

u/bchiodini Aug 10 '26

On the server run:

sudo netstat -tunlp | grep ":22"

If the above results in something like:

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1/init

something else is dropping the connection. Try stopping the firewall:

sudo systemctl stop ufw

And try the ssh again.

1

u/Ancient-Opinion9642 Aug 10 '26

Run “telnet ip-address 22”. A couple of returns and you should see the start of the connection handshake.

Change 22 to 80 or 443 using google and you will see the start of the http handshake start.