Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.


What exactly causes a ssh connection to interrupt? When you idle for a while, it disconnects.

How do I keep the connection alive (without autossh or reconnect)?

share|improve this question

2 Answers 2

This is most likely a firewall which cuts your idle connection after a while.

You can configure the openssh server or client to send a KeepAlive after a while.

Send a KeepAlive every 5 minutes to the server:

ssh user@server -o ServerAliveInterval=300

If you have control over the openssh-server, you can also send KeepAlives to the client after a defined interval. Add the following to /etc/ssh/sshd_config:

ClientAliveInterval 300
TCPKeepAlive yes

TCPKeepAlive should be yes by default.

Restart the openssh-server after the modification:

/etc/init.d/ssh restart
share|improve this answer

Here are a few things you can try:

1) It's most likely the shell which is timing out. Disable the timeout by unsetting TMOUT in your profile. TMOUT is the number of seconds that bash waits for input before terminating. Echo $TMOUT to see if it is set. Add the following to your profile:

unset TMOUT

2) Configure PuTTY to send keepalive packets by going into:

Settings > Connection > Seconds between keepalives = 60

3) Tweak your sshd_config (normally found in /etc/ssh) and add:

TCPKeepAlive yes
ClientAliveInterval 60

Save the file and restart sshd.

share|improve this answer
    
in theory this should always make the connection established? i will try ClientAliveInterval –  c2h2 Jan 19 '11 at 17:53
    
This works great!!!! havn't disconnected for 24 hours, where normally breaks every hour. –  c2h2 Jan 20 '11 at 9:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.