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

5/5 – (1 vote)

Problem Formulation

I just tried to run AutoGPT on an EC2 instance using SSH from my local Windows machine. But here’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 and restart the program.

[Image: 2694.png] Problem Formulation: 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.

Quick and Easy Solution (Client-Side)

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.

Create a configuration file in your home directory at
Code:
$HOME/.ssh/config
, and set its permissions to
Code:
600
using
Code:
chmod 600 ~/.ssh/config
after file creation. To send a keep-alive signal every 240 seconds, for example, add the following lines to the configuration file:

Code:
Host * ServerAliveInterval 240

You can get this done with the following two commands on Linux:

Code:
printf '%s\n' 'Host *' ' ServerAliveInterval 240' > ~/.ssh/config chmod 600 ~/.ssh/config

You can then check the file content using the command
Code:
cat ~/.ssh/config
like so:

[Image: image-186.png]
Alternative Solution: Server Side

In some cases, you have access to the server’s SSH settings. In that case, add an entry
Code:
ClientAliveInterval 60
to the file
Code:
/etc/ssh/sshd_config
. I used the Vim editor in the terminal to accomplish this.

[Image: image-187.png]

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:
Reply

Users browsing this thread:
1 Guest(s)

Forum Jump: