{"id":133193,"date":"2023-04-18T18:29:45","date_gmt":"2023-04-18T18:29:45","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=1302633"},"modified":"2023-04-18T18:29:45","modified_gmt":"2023-04-18T18:29:45","slug":"keep-ssh-session-alive","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2023\/04\/18\/keep-ssh-session-alive\/","title":{"rendered":"Keep SSH Session Alive"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;1302633&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;starsonly&quot;:&quot;&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;title&quot;:&quot;Keep SSH Session Alive&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/p><\/div>\n<h2 class=\"wp-block-heading\">Problem Formulation<\/h2>\n<p>I just tried to run <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/what-is-autogpt-and-how-to-get-started-your-quick-guide-to-success\/\" data-type=\"post\" data-id=\"1292053\" target=\"_blank\">AutoGPT<\/a> on an EC2 instance using SSH from my local Windows machine. But here&#8217;s the annoying part: <strong>the connection always closes and AutoGPT can only work in small ~10 minute increments<\/strong>. When I return to my machine, I need to SSH into my instance and restart the program.<\/p>\n<p class=\"has-global-color-8-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/2694.png\" alt=\"\u2694\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Problem Formulation<\/strong>: Your SSH connection to a remote server works properly at your workplace, but it freezes after 10-15 minutes when connecting from home. You don&#8217;t receive any error messages, but you notice zombie login users that need to be killed manually.<\/p>\n<h2 class=\"wp-block-heading\">Quick and Easy Solution (Client-Side)<\/h2>\n<p>To prevent an SSH connection from closing when the client goes silent, you can configure the client to send a keep-alive signal to the server periodically. <\/p>\n<p>Create a configuration file in your home directory at <code>$HOME\/.ssh\/config<\/code>, and set its permissions to <code>600<\/code> using <code><code>chmod 600 ~\/.ssh\/config<\/code><\/code> after file creation. To send a keep-alive signal every 240 seconds, for example, add the following lines to the configuration file:<\/p>\n<pre class=\"wp-block-preformatted\"><code>Host * ServerAliveInterval 240<\/code><\/pre>\n<p>You can get this done with the following two commands on Linux:<\/p>\n<pre class=\"wp-block-preformatted\"><code>printf '%s\\n' 'Host *' ' ServerAliveInterval 240' &gt; ~\/.ssh\/config\nchmod 600 ~\/.ssh\/config<\/code><\/pre>\n<p>You can then check the file content using the command <code>cat ~\/.ssh\/config<\/code> like so:<\/p>\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"986\" height=\"168\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/04\/image-186.png\" alt=\"\" class=\"wp-image-1302658\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/04\/image-186.png 986w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/04\/image-186-300x51.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/04\/image-186-768x131.png 768w\" sizes=\"auto, (max-width: 986px) 100vw, 986px\" \/><\/figure>\n<h2 class=\"wp-block-heading\">Alternative Solution: Server Side<\/h2>\n<p class=\"has-base-2-background-color has-background\">In some cases, you have access to the server&#8217;s SSH settings. In that case, add an entry <code>ClientAliveInterval 60<\/code> to the file <code>\/etc\/ssh\/sshd_config<\/code>. I used the Vim editor in the terminal to accomplish this.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"776\" height=\"517\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/04\/image-187.png\" alt=\"\" class=\"wp-image-1302803\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/04\/image-187.png 776w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/04\/image-187-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2023\/04\/image-187-768x512.png 768w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><\/figure>\n<\/div>\n<p>Do you want to keep improving your coding and tech skills? Feel free to check out our Python and tech academy by downloading your free cheat sheets for starters:<\/p>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) Problem Formulation I just tried to run AutoGPT on an EC2 instance using SSH from my local Windows machine. But here&#8217;s the annoying part: the connection always closes and AutoGPT can only work in small ~10 minute increments. When I return to my machine, I need to SSH into my instance [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-133193","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/133193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=133193"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/133193\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=133193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=133193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=133193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}