{"id":6538,"date":"2015-12-25T20:35:30","date_gmt":"2015-12-25T12:35:30","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=6538"},"modified":"2023-04-28T09:47:08","modified_gmt":"2023-04-28T09:47:08","slug":"prevent-ssh-timing-out","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/prevent-ssh-timing-out\/","title":{"rendered":"How to Prevent SSH Timing out from Server and Client"},"content":{"rendered":"<p><img decoding=\"async\" class=\"alignnone wp-image-6539 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/11\/coding-926242_1280.jpg\" alt=\"Prevent SSH Timing out\" width=\"1280\" height=\"853\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/11\/coding-926242_1280.jpg 1280w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/11\/coding-926242_1280-300x200.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/11\/coding-926242_1280-768x512.jpg 768w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/11\/coding-926242_1280-1024x682.jpg 1024w\" data-sizes=\"(max-width: 1280px) 100vw, 1280px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1280px; --smush-placeholder-aspect-ratio: 1280\/853;\" \/><\/p>\n<p>As a system administrator, you manage linux servers and for some others may have their own virtual private server (VPS). \u00a0In some cases you will need to spend a lot of time on the SSH connection to resolve any issues and do the routine work through command line. Some of you may have encountered an annoying issue where your session is disconnected after a period of inactivity.<\/p>\n<p>SSH connection that is inactive or idle usually disconnected by the server after a specified period of time. It depends on the configuration in the SSH server(remote server) or the SSh client. \u00a0After the connection is cut, the client SSH \/ putty connection you will be presented with a message saying SSH time out or connection closed or message similar to below :<\/p>\n<pre>Read from remote host www.ehowstuff.com: Connection reset by peer Connection to www.ehowstuff.com closed\n<\/pre>\n<p>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. This article will<\/p>\n<p>As the reference, i will explains how you can stop and prevent SSH timing out from server and client. This steps has been tested on CentOS 6 \/ CentOS 7 \/ RHEL 6 \/ RHEL 7 \/  Oracle Linux 6 \/ Oracle Linux 7.<\/p>\n<h3>What is \/etc\/ssh\/sshd_config ?<\/h3>\n<p>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)<\/p>\n<h3>What is \/etc\/ssh\/ssh_config ?<\/h3>\n<p>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.<\/p>\n<h3>Option 1 : How to Prevent SSH Timing out from OpenSSH Server :<\/h3>\n<p>a) As a root user, open sshd_config file :<\/p>\n<pre># vi \/etc\/ssh\/sshd_config\n<\/pre>\n<p>b) Find the ClientAliveInterval option to 60 (in seconds) or add the value if it is not there.<\/p>\n<pre>ClientAliveInterval 60\n<\/pre>\n<p>Note : ClientAliveInterval: number of seconds that the server will wait before sending a null packet to the client (to keep the connection alive).<\/p>\n<p>c) Restart sshd daemon :<br \/>\nIn CentOS 7 \/ RHEL 7<\/p>\n<pre># sudo systemctl restart sshd.service\n<\/pre>\n<p>In CentOS 5\/6 \/ RHEL 5\/6<\/p>\n<pre># service sshd restart\n<\/pre>\n<p>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<br \/>\na response from the client. If no response, ssh server will let ssh client to exit (timeout) automatically.<\/p>\n<h3>Option 2 : How to Prevent SSH Timing out from Linux OpenSSH Client :<\/h3>\n<p>a) As a root user, open ssh_config file :<\/p>\n<pre># vi \/etc\/ssh\/ssh_config\n<\/pre>\n<p>b) Find the ServerAliveInterval option to 60 (in seconds) or add the value if it is not there.<\/p>\n<pre>ServerAliveInterval 60\n<\/pre>\n<p>Note : ServerAliveInterval: number of seconds that the client will wait before sending a null packet to the server (to keep the connection alive).<\/p>\n<p>In above example, we set a timeout interval to 60 seconds after idle time, ssh client will send a message through the encrypted channel to request a response from the server, so that the server won\u2019t disconnect the client.<\/p>\n<h3>Option 3 : How to Prevent SSH Timing out from Windows Putty Client :<\/h3>\n<p>a) Open Putty<br \/>\nb) Click on Connection tab<br \/>\nc) Check the box for Enable TCP keepalives (SO_KEEPALIVE option)<br \/>\nd) Input the second in between keepalives.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-6563 size-full lazyload\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/12\/Putty-disable-ssh-time-out-1.png\" alt=\"Prevent SSH Timing out\" width=\"454\" height=\"431\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/12\/Putty-disable-ssh-time-out-1.png 454w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2015\/12\/Putty-disable-ssh-time-out-1-300x285.png 300w\" data-sizes=\"(max-width: 454px) 100vw, 454px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 454px; --smush-placeholder-aspect-ratio: 454\/431;\" \/><\/p>\n<h3>Conclusion<\/h3>\n<p>All of above settings will let the server or client send a packet to its partner every 60 seconds. After the configuration is done, SSH connection will remain active even if the user does not perform any activity at the command line or idle.<\/p>\n<p>Reference<br \/>\n<a href=\"https:\/\/sysadmincasts.com\/episodes\/39-cli-monday-how-to-keep-your-ssh-sessions-alive\" target=\"_blank\" rel=\"noopener\">sysadmincasts.com<\/a><br \/>\n<a href=\"https:\/\/www.simplified.guide\/ssh\/disable-timeout\" target=\"_blank\" rel=\"noopener\">docs.oseems.com<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As a system administrator, you manage linux servers and for some others may have their own virtual private server (VPS). \u00a0In some cases you will need to spend a lot&#8230;<\/p>\n","protected":false},"author":6,"featured_media":6539,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1058],"tags":[1622],"class_list":["post-6538","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ssh","tag-openssh"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=6538"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/6538\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/6539"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=6538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=6538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=6538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}