When using Putty for SSH connections via command line, sessions often timeout after periods of inactivity. This happens because:
- Network devices (routers/firewalls) drop idle TCP connections
- Default Putty configuration doesn't send keepalive packets
- SSH servers may terminate inactive sessions
To enable keepalive directly in your Putty command line:
putty.exe -ssh user@192.11.11.11 -pw mypassword -serial -keepalive 60
Key parameters:
-keepalive 60
: Sends keepalive packet every 60 seconds (adjust as needed)-serial
: Required for keepalive to work with command line connections
Saved Session Configuration
For frequently used connections:
- Launch Putty GUI
- Configure keepalive under Connection → Seconds between keepalives
- Save session
- Call from command line:
putty.exe -load "SavedSessionName" -ssh user@host -pw password
Registry Modification
For permanent system-wide settings:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings]
"Keepalive"="60"
"PingIntervalSecs"="60"
"PingInterval"="60"
- If keepalive isn't working, try decreasing the interval (e.g., 30 seconds)
- Some corporate networks may block ICMP packets - try TCP keepalive instead
- Combine with server-side configuration (ClientAliveInterval in sshd_config)
For a production-ready command with all options:
putty.exe -ssh admin@prod-server.example.com -pw S3cur3P@ss
-serial -keepalive 30 -no-antispoof -ssh-connection-timeout 0
When using Putty from command line with basic authentication:
putty.exe -ssh user@192.11.11.11 -pw mypassword
The connection may timeout after a few minutes of inactivity, especially when working through firewalls or NAT devices that drop stale connections.
Putty supports two complementary approaches to maintain connection persistence:
putty.exe -ssh user@host -pw password -serial 60 -keepalive 30
Where:
- -serial: Sets the keepalive packet interval in seconds (default 0 = disabled)
- -keepalive: Configures TCP keepalive packets (SO_KEEPALIVE)
For enterprise environments with strict firewall policies, consider these additional parameters:
putty.exe -ssh user@host -pw password \
-serial 45 \
-keepalive 15 \
-no-antispoof \
-ssh -serial-log=keepalive.log
For Windows systems where you want persistent settings across sessions:
reg add "HKCU\Software\SimonTatham\PuTTY\Sessions\Default%20Settings" \
/v "PingInterval" /t REG_DWORD /d 60 /f
reg add "HKCU\Software\SimonTatham\PuTTY\Sessions\Default%20Settings" \
/v "PingIntervalSecs" /t REG_DWORD /d 30 /f
If keepalives aren't working, test your network path with:
ping -t host
tcping host 22
Check for intermediate devices that might be dropping packets:
tracert host
pathping host