Here is how to keep your ssh session from freezing and how to keep ssh alive.
Edit your ssh config file. Change to the following variables
# nano /etc/ssh/sshd_config
TCPKeepAlive yes ClientAliveInterval 60 ClientAliveCountMax 10000
Then, restart ssh
# service sshd restart Stopping sshd: [ OK ] Starting sshd: [ OK ]
- TCPKeepAlive – is there to ensure that certain firewalls don’t drop idle connections.
- ClientAliveInterval – the server will wait 60 seconds before sending a null packet to the client to keep the connection alive.
- ClientAliveCountMax – server will send alive messages to the client even though it has not received any message back from the client.
Using Putty Settings
- Start PuTTY.
- Load pone of your saved sessions.
- In the Category pane, click Connection.
- Look for ” Sending of null packets to keep session active”.
- In the Seconds between keepalives (0 to turn off), type 300. (With this configuration, PuTTY sends a packet to the server every 300 seconds -5 minutes – to keep the connection alive.
- In the Category pane, click Session.
- Click Save.
- Connect to your account and monitor the connection. If it still drops, gradually decrease the keepalive interval until the connection is stable.