04-19-2023, 12:47 AM
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.
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, and set its permissions to using after file creation. To send a keep-alive signal every 240 seconds, for example, add the following lines to the configuration file:
You can get this done with the following two commands on Linux:
You can then check the file content using the command like so:
![[Image: image-186.png]](https://blog.finxter.com/wp-content/uploads/2023/04/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 to the file . I used the Vim editor in the terminal to accomplish this.
![[Image: image-187.png]](https://blog.finxter.com/wp-content/uploads/2023/04/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:
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.
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/configCode:
600Code:
chmod 600 ~/.ssh/configCode:
Host * ServerAliveInterval 240You can get this done with the following two commands on Linux:
Code:
printf '%s\n' 'Host *' ' ServerAliveInterval 240' > ~/.ssh/config
chmod 600 ~/.ssh/configYou can then check the file content using the command
Code:
cat ~/.ssh/config![[Image: image-186.png]](https://blog.finxter.com/wp-content/uploads/2023/04/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 60Code:
/etc/ssh/sshd_config![[Image: image-187.png]](https://blog.finxter.com/wp-content/uploads/2023/04/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:

