![]() |
|
[Tut] Keep SSH Session Alive - Printable Version +- Sick Gaming (https://sickgaming.net) +-- Forum: Programming (https://sickgaming.net/forum-76.html) +--- Forum: Python (https://sickgaming.net/forum-83.html) +--- Thread: [Tut] Keep SSH Session Alive (/thread-100995.html) |
[Tut] Keep SSH Session Alive - xSicKxBot - 04-19-2023 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 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![]() 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![]() 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: |