port 22: Connection refused

December 4, 2013 18.5k 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 :/
16 Answers
Turns out I was using a VPN that blocked port 22. Now everything is working properly.
You tried other SSH clients? Alternatively, check using nmap-if port 22 is not used by any service or firewall.
Are you trying to connect after a fresh install? Or, perhaps, is there a firewall deployed or the SSH port got changed?
@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!

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.

  • so what should I do if my port is 2500 what should I change in my ssh command?

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....

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.

Have another answer? Share your knowledge.