Linux Administrator

Fixed :- SSH Connection Timeout or Increase SSH session Time in Unix/Ubuntu

SSH clients will automatically be disconnected from the server and prompt the below message after being idle or inactive for a while.

Read from remote host Connection reset by peer Connection to closed.

This is due to the SSH servers’ configuration (often by default) to avoid hanging sessions and free up resources.

In order to prevent SSH timing out from the server, you need to configure /etc/ssh/sshd_config or /etc/ssh/ssh_config. If we keep the setting a value of 0 (the default) for both (ServerAliveInterval and ClientAliveInterval) will disable these features so your connection could drop if it is idle for too long.

In this article I will show how you can fix the SSH connection timeout.

What is sshd_config?

sshd_config is a system configuration file for OpenSSH which allows you to set options that modify the operation of the daemon (SSH server/service).

What is sshd_config?

ssh_config is a system configuration file for OpenSSH which allows you to set options that modify the operation of the linux client programs. If you are running windows client program you should configure it in Putty client.

Fix SSH Connection Timeout

As a root user edit the sshd_config file.

# vim /etc/ssh/sshd_config

Find the ClientAliveInterval option to 60 (in seconds) or add the value if it is not there.

ClientAliveInterval 60
ClientAliveInterval: number of seconds that the server will wait before sending a null packet to the client (to keep the connection alive).

Now restart the sshd service.

On CentOS7/RHEL7 :

# systemctl restart sshd.service

on CentOS5/6/RHEL5/6/ :

# service sshd restart

In above example, we sets a timeout interval to 60 seconds after idle time (which if no data has been received from the client), the ssh server will send a message through the encrypted channel to request a response from the client. If no response, ssh server will let ssh client to exit (timeout) automatically.

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment