i tried to ssh root@ipaddress. I received error port 22 connection refused

May 2, 2017 15.3k views
Ansible Ubuntu 16.04

i tried to ssh root@ipaddress. I received error port 22 connection refused. Can you help with this?

3 Answers

Hi @stanhao

Have you changed the port of the SSH server? If yes, then you need to change on the client too, meaning connecting with -p like:
ssh -p 22 root@domain_or_ip

Maybe you activated the firewall, but forgot to allow port 22?
This means you're locked out. You can go to the control panel of DigitalOcean and access your droplets console, where you can allow port 22 thru the firewall with this command:
sudo ufw allow 22

Or you have a IPS like fail2ban, which has blocked you for some reason. Go to the console and restart fail2ban, which normally clears any blocking:
service fail2ban restart

  • I have one machine with ubuntu installed. When you mean SSH server, do you mean a separate host machine? You mentioned "client", are you referring to my Ansible client machine?

    • I mean the SSH daemon running on your server. And the SSH client you're using on your computer.


To login via SSH, you'll need to get your Droplet's Public IPv4 address from the DigitalOcean Control Panel. You'd then login using either:

ssh root@droplet_ip

or, if you're using SSH Keys:

ssh root@droplet_ip -i /path/to/private_key

Where /path/to/private_key is the direct path to the private key that's associated with the public key that should be in ~/.ssh/authorized_keys on your Droplet.

The above works if your on a Mac or Linux box using Terminal or another similar application. If you're on Windows, you'll need to use PuTTy or something similar and create a session as PuTTy doesn't work like a standard Terminal application does (in terms of how you login) -- at least not the GUI version.

resolved. ssh was not installed correctly

apt-get install openssh-server openssh-client

Have another answer? Share your knowledge.