SSH is the most secure means of connecting to Linux servers remotely. And one of the common errors encountered while using SSH is the “ssh: connect to host port 22: No route to host”. In this short article, we will show how to troubleshoot and fix this error.

Here is a screenshot of the error we are talking about. Note that the port may not necessarily be port 22, depending on your configurations on the remote host. As a security measure, system administrators can configure SSH to be accessed via a different port.

[email protected]:~$ ssh [email protected]
ssh: connect to host 192.168.56.100 port 22: no route to host
[email protected]:~$

There are different reasons why this error appears. The first is normally that the remote server could be down, so you need to check whether it is up and running using the ping command.

# ping 192.168.56.100

[email protected]:~$ ping 192.168.56.100
PING 192.168.56.100 (192.168.56.100) 58(84) bytes of data.
64 bytes from 192.168.56.100: icmp_seq=1 ttl=64 time=0.531 ms
64 bytes from 192.168.56.100: icmp_seq=1 ttl=64 time=0.560 ms
64 bytes from 192.168.56.100: icmp_seq=1 ttl=64 time=0.574 ms
64 bytes from 192.168.56.100: icmp_seq=1 ttl=64 time=0.593 ms
64 bytes from 192.168.56.100: icmp_seq=1 ttl=64 time=0.542 ms
64 bytes from 192.168.56.100: icmp_seq=1 ttl=64 time=0.685 ms
64 bytes from 192.168.56.100: icmp_seq=1 ttl=64 time=0.631 ms
64 bytes from 192.168.56.100: icmp_seq=1 ttl=64 time=0.501 ms
^C
--- 192.168.56.100 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5090ms
rrt min/avew/max/mdev = 0.545/0.601/0.685/0.115 ms
[email protected]:~$

From the ping command results, the server is up and running; that’s why it is accepting the pings. In this case, the reason for the error is something else.

If you have a firewall service running on your remote server, it is possible that the firewall is blocking access via port 22.

Therefore, you need to physically access the server console, or if it is a VPS, you can use any other means such as VNC (if it is already set up) or other custom remote server access applications provided by your VPS service provider. Log in and access a command prompt.

Then use the firewall-cmd (RHEL/CentOS/Fedora) or UFW (Debian/Ubuntu) to open port 22 (or the port you configured to be used for SSH) in the firewall as follows.

# firewall-cmd --permanent --add-port=22/tcp
# firewall-cmd --reload
OR
$ sudo ufw allow 22/tcp
$ sudo ufw reload 

Now try to reconnect to the remote server once more via SSH.

$ ssh [email protected]
[email protected]:~$ ssh [email protected]
[email protected]'s password:
Last loging: Thu Jul 4 05:53:33 2017
[root@server1 ~]#
[root@server1 ~]# w
 04.47:03 up 51 min,  2 ysers.  load averae: 0.00, 0.00, 0.00
USER     TTY      FROM             LOGIN$  IDLE   JCPU    PCPU WHAT
root     tty1     -                05:53   2:20   0.02s   0.02s -bash
root     pts/.0   192.168.56.1     05:56   3.00a  0.04s   0.03s w
Thats it, for now!