Create an account


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] Keep SSH Session Alive

#1
Keep SSH Session Alive

<div>
<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;}'>
<div class="kksr-stars">
<div class="kksr-stars-inactive">
<div class="kksr-star" data-star="1" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="2" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="3" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="4" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" data-star="5" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
<div class="kksr-stars-active" style="width: 142.5px;">
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
<div class="kksr-star" style="padding-right: 5px">
<div class="kksr-icon" style="width: 24px; height: 24px;"></div>
</p></div>
</p></div>
</div>
<div class="kksr-legend" style="font-size: 19.2px;"> 5/5 – (1 vote) </div>
</p></div>
<h2 class="wp-block-heading">Problem Formulation</h2>
<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’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>
<p class="has-global-color-8-background-color has-background"><img src="https://s.w.org/images/core/emoji/14.0.0/72x72/2694.png" alt="⚔" 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’t receive any error messages, but you notice zombie login users that need to be killed manually.</p>
<h2 class="wp-block-heading">Quick and Easy Solution (Client-Side)</h2>
<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>
<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>
<pre class="wp-block-preformatted"><code>Host * ServerAliveInterval 240</code></pre>
<p>You can get this done with the following two commands on Linux:</p>
<pre class="wp-block-preformatted"><code>printf '%s\n' 'Host *' ' ServerAliveInterval 240' &gt; ~/.ssh/config
chmod 600 ~/.ssh/config</code></pre>
<p>You can then check the file content using the command <code>cat ~/.ssh/config</code> like so:</p>
<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/uplo...300x51.png 300w, https://blog.finxter.com/wp-content/uplo...68x131.png 768w" sizes="(max-width: 986px) 100vw, 986px" /></figure>
<h2 class="wp-block-heading">Alternative Solution: Server Side</h2>
<p class="has-base-2-background-color has-background">In some cases, you have access to the server’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>
<div class="wp-block-image">
<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/uplo...00x200.png 300w, https://blog.finxter.com/wp-content/uplo...68x512.png 768w" sizes="(max-width: 776px) 100vw, 776px" /></figure>
</div>
<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>
</div>


https://www.sickgaming.net/blog/2023/04/...ion-alive/
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum software by © MyBB Theme © iAndrew 2016