How to resolve and prevent “SSH timeout server not responding”?

Users frequently get the ssh timeout error while they are configuring the server with some important changes. Getting this error can be quite frustrating and it will affect the functioning of the server. The most common causes of this error can be incorrect IP hosts, wrong server settings, restrictions in the firewall, etc.

Here, in this article, we will try to understand these errors in detail and learn how to resolve them. We shall also learn how to avoid the ssh connection timed-out error from happening.


Explanation: Server SSH Timeout

SSH provides a secure method of logging into a machine remotely. It secures your login activity on a suspicious and insecure network. Services such as remote command execution, login, etc can be executed with high security using SSH. In most cases, session timeout means the user is not active. Here, the status of an inactive user becomes invalid. “ssh timeout server not responding” message will be displayed to the user. An example of the error message is mentioned below where aa.aa.aa.aa denotes the host IP.

ssh: connect to host aa.aa.aa.aa port 22: Connection timed out

Reasons and Solutions for the SSH Timeout Error

  • Hosts are Wrong

    Incorrect SSH host name or out of date IP address given by the users can be the probable cause of the ssh not responding error. 

You should check the SSH connection details first. It must be checked that the user detail and host IP address are mentioned correctly without any typing errors.

  • SSH Port is Changed

    Occasionally, it is also seen that many users edit the SSH port 22 to some other port in the server settings. The timeout error will pop up when the user tries to establish a connection.

    We can use the following command to check the SSH port:

    netstat -l | grep ssh

    This will let you know the exact SSH port being used. We can then verify the port parameters by looking at the SSH configuration file present at the /etc/ssh/sshd_config location.

  • Restrictions in Firewall

    Restriction in the firewall settings can also be a common reason for this error. Port blocks in networks or specific settings on the server can be a cause for this.

    Begin by looking at the firewall settings and ensuring nothing is causing the ssh connection timed out error. We can look at the iptables to check any IP restriction by using the following command:

    iptables -nL | grep xx.xx.xx.xx

    Just removing the IP restrictions will fix this error.

How can we keep the SSH timeout error at bay?

We have covered the causes and solutions of this error. We shall now see how we can keep this error away from our server by tweaking the configuration settings.

  • Settings at Client’s Side

    Let us see how to edit the session timeout value on the client’s end. The ~/.ssh/config file must be edited to avoid the session timeout error. You can add the below-mentioned code in the configuration file:

    Host *
    ServerAliveInterval 120
    ServerAliveCountMax 2

What this means is that a null packet is being sent two times to the server at an interval of 120 seconds so that the session remains alive.

  • Settings at Sever’s Side

    Error in settings on the server end can also affect the connection on the client end. We can edit the configuration file to avoid this easily. The following code must be added to the configuration file located at /etc/ssh/sshd_config.

    KeepAlive yes
    ClientAliveInterval 120
    ClientAliveCountMax 2

This indicates that a null packet is being forwarded two times to the server, each time at a 120-second interval. This will prevent the SSH connection from being timed out.


We have successfully learned all the causes and the solutions to resolve the ‘ssh timeout error’. It can be caused due to restrictions in the firewall, wrong server settings, and incorrect host addresses. Here, we also learned how to prevent and avoid this error from happening in our system and affecting our connection.