Increase timeout os ssh connection

I ssh to a remote linux box.. And always after 30 minutes or so i am not sure about the exact timings the connection gets broken if the terminal is left idle.
I am connecting to box using ssh command from my Mac terminal.
how can i keep the connection running...?
I can think of two ways but dont know how to do it.
1) Do something on the terminal so it doesnot remain idle...
2) increase the timeout
Please suggest
Rohit BajajAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nociSoftware EngineerCommented:
This most probably happens because there is no traffic when the link is idle.
You can enable that by setting TCPkeepalive option in ssh_config.

This wil send an empty message accross the link to keep all network timers happy as there is still some traffic.

Most Firewalls will drop TCP connection entries after some time passwed without any traffic seen.
Either put it in the systemwide /etc/ssh/ssh_config  or user private config: ~/.ssh/config

or pass it as an Option: ssh -oTCPKeepAlive=yes user@remotehost
Apurva BhandariLinux/Cloud/DB/DevOpsCommented:
try to set in sshd_config file
ServerAliveInterval 120
ServerAliveCountMax 30
ConnectTimeout 30

This will make the server send the clients a “null packet” every 120 seconds and not disconnect them until the client have been inactive for 720 intervals (120 seconds * 720 = 86400 seconds = 24 hours).
sshd_config file
ClientAliveInterval 120
ClientAliveCountMax 720

after this restart the sshd service

To disable auto-logout, just set the TMOUT to zero or unset
#export TMOUT=0
#unset TMOUT
Prabhin MPEngineer-TechOPSCommented:
create a file in your home directory,
vi .ssh/config
and add the following
Host *
ServerAliveInterval 120
ServerAliveCountMax 30
ConnectTimeout 30

Just do a ssh service restart.

Now you won't be kicked out from ssh access even though you are iDLE.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Prabhin MPEngineer-TechOPSCommented:
perfect answer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.