port 22: Connection refused

Posted December 4, 2013 77.4k views
I was trying to log in my server through Mac Terminal. I typed 'ssh root@ipaddress' and it gives me 'ssh: connect to host ipaddress port 22: Connection refused'. how should I log in? I just forgot :/

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

19 answers
You tried other SSH clients? Alternatively, check using nmap-if port 22 is not used by any service or firewall.

I have solved this issue by unchecking the SSH key.

I have set an ssh key for the previous droplet. When I try to use the same ssh key for the new droplet it refused me to connect on port 22. I destroyed and created a new droplet and did not choose the ssh key. When I got the e-mail for the password it worked using that password.

Turns out I was using a VPN that blocked port 22. Now everything is working properly.

I Had the same issue, but with the sudo netstat -plutn | grep 22
i realized that my real port was changed to 2500, and not 22 anymore.
but now it’s working properly.

For ubuntu 16 this worked for me

from the console

$ sudo service sshd restart

Are you trying to connect after a fresh install? Or, perhaps, is there a firewall deployed or the SSH port got changed?
Same thing here, fresh install, snapshot
@max: Do you have a firewall installed on your droplet? Can you log in using the remote console?
I'm having the exact same issue. I can log in using the Console but can't ssh in from terminal or via SFTP. I didn't intentionally install a firewall on my droplet. How would I check for that? This is a new droplet created from a snapshot image.
I took a snapshot and then tried to launch a larger droplet and now I'm locked out of both.

I'm getting: ssh: connect to host port 22: Connection refused
@ajb: Try logging into your droplet using the remote console and running
sudo netstat -plutn
do you see an instance of openssh/a program listening on port 22 there?
Hello same issue on fresh dropplet image installations
Same issue here. Created a fresh droplet choosing Wordpress on Ubuntu 13.10 as the droplet type. Tried 'ssh' and recieving ssh: connect to host port 22: Connection refused
as the error.

Is that port blocked on default installation?

Having same problem, anyone found the solution?

  • Is it based on an Application image? If so, try waiting a few minutes before trying to connect while the droplet is being configured. If not, try logging into your droplet using the Remote Console and running sudo netstat -plutn | grep 22, does it output a line with “sshd” in it?

    • @kamaln7 , I can’t connect to my IP address using my browser (so somehow similar problem). I ran the command and here’s what happened:

      sudo netstat -plutn | grep 22
      tcp        0      0    *               LISTEN      1706/sshd
      tcp6       0      0 :::22                   :::*                    LISTEN      1706/sshd

      Could you please help me figure out what the problem is?


      • Hi @emisaghi, that command is checking for processes that are listening on port 22, which is used for SSH access. Browsers use port 80 for HTTP by default, so I would start by checking if you have a webserver installed and running that is listening on that.

        If you’ve installed a webserver already, simply run the same command as mentioned before, replacing the 22 with 80 and see if you get any results.

        If you don’t know whether or not you’ve installed a webserver (e.g. Apache or nginx), can you tell me more about what image you have built your Droplet from and what you have installed on it?

        • Thanks for your prompt response. I actually had the server listening to port 80, too and it was a 1-click WordPress 4.6.1 on Ubuntu 16.04. Unfortunately, because of all the trouble, I had to destroy the droplet and create a new one. The new one works, but I haven’t configured Varnish or swap on it, yet. I’ll try those and see if any of the steps in those is actually causing the problem.

          Thanks again!

It seems that Droplets by default listen at 2200 for the ssh
use 2200 instead 22

I’m having the exact same problem since a letsencrypt certificate expired not connection to port 22
what do I do as I cannot access via console either....

Did anyone find the answer? I’m still stuck with this issue for several months now and it’s a real pain. I can’t access my filezilla anymore even though I used to!

When I did sudo netstat -plutn | grep 22 from the console, it gave me the following

tcp        0  *       LISTEN   1064/postgres
tcp        0  *       LISTEN      1291/master
tcp        0  *       LISTEN      1019/mysqld
tcp        0      0  *       LISTEN      1706/sshd
tcp6        0      0::::00  *       LISTEN      1364/apache2
tcp6        0      0:::1:25  *       LISTEN      1291/master

Thank you all so much!

I was getting Connection refused after I typed in the wrong password in ssh. After I logged in successfully from the Digital Ocean Console, I was able to log in successfully with ssh.

Submit an Answer