Keeping SSH Sessions Alive February 3, 2006
Posted by Carthik in administration, snippets, ubuntu.trackback
Scott Merrill writes in to say:
I noticed recently that ssh connections from my Ubuntu laptop to my
Debian server would time out and disconnect if I left the connection
idle for a long-ish period of time. This really annoyed me, because my
Debian desktop does not exhibit this behavior when connecting to the server.I added the following line to
/etc/ssh/ssh_config
:
ServerAliveInterval 5
That seems to have fixed the problem, and my laptop can now remain
connected, though idle, to my server. Maybe this will help someone
else, too.
What this does, essentially is every 5 seconds, the client sends a small keep-alive packet to the server to make it look like the ssh connection is being actively used. The reason for Scott’s timeout could be a NAT firewall that seeks to minimize the nember of active connections to reduce its memory footprint, or to improve performance for other clients. Most firewalls and networks let you keep your connections alive for as long as you wish, but some may act up, and that’s when you can use Scott’s trick.
Tip: Change 5 to 240 or 300, so that instead of every 5 seconds, the keep-alive signal is sent only once in 4 or 5 minutes 🙂
Sorry it took me so long to post this useful tip, Scott.
The point of dropping the connection is a security one, though. I let mine time out after idling for that reason. Just sayin’.
I’m using gnu screen with a status line that displays the time, and as this is refreshed every minute, its enough.
[…] This post from Scott Merril explains how to keep SSH sessions alive. […]
On the Ubuntu SSH server side (sshd_config) I inserted these lines:
ClientAliveInterval 60
ClientAliveCountMax 60
and got pretty much the same result, although it says 60min, it doesn’t disconnect (time out) ssh clients. It really annoyed me before…
hey, great stuff……any idea how i can resume a ssh session…
im no expert, so i’d thought you’d be able to harness your contacts and resevoir of knowledge.
ie i start a ssh session to my exclusive torrent box, and start some torrents via bitttorrent-ncurses, then either leave the sessions, or maybe my ssh client machine dies.
how do i resume a ssh session.
woops. how do i resume the session, and keep an eye on the progress of the torrents.
or are programs that are executed by a remote ssh client always killed upon client exiting the session?
airtonix: apt-get install screen
(then lookup the man page for it on how to detach and re-attach sessions)
That man page is really for looking up known information. I’d suggest taking a look at McPherson’s tutorial (originally from kuro5hin): http://jmcpherson.org/screen.html
[…] El caso es que se me ha ocurrido que esto debera estar ya pensado en SSH, por ejemplo enviando un Keep-Alive, y efectivamente es as. En Keeping SSH connections alive lo he encontrado. Y parece que funciona. Related posts in t8i References in t8i […]
[…] Keeping SSH Sessions Alive « Ubuntu Blog (tags: linux ubuntu howto) […]
You can also make this change in your home directories .ssh folder.
In the file, replace “username” with your name, create a text file if it doesn’t exist:
/home/username/.ssh/config
make the following entries:
serveraliveinterval 60
serveralivecountmax 10
Adjust as you see fit.
Is there any way to specify a idle/timeout setting when initiating the ssh client session to the remote server? I would like to not modify the default behavior of SSH, just a single instance from time to time. If possible, please post here would be a nice addition.
[…] Technical Cons. – Initial connections and DNS lookups are rubbish. It takes several seconds for DNS queries to complete. New ssh connections take about 5 seconds to come up. – It’s NATed. You don’t seem to get a real IP number and you can’t make inbound connections. – It dropped ssh connections like nobodie’s business. This was becoming a real issue until I realised why it was happening; you just need to set an ssh keep alive. […]
[…] Keeping SSH Sessions Alive « Ubuntu Blog […]
[…] agressive NAT gateway which is timing out your connections as fast as it can. You just need to set an ssh keep alive. – There seems to be a transparent http proxy involved. You can’t access an http svn […]
[…] Quelle: ubuntu.wordpress.com […]
Q. How to add a status line to “screen” that displays the time?
A. Add this to ~/.screenrc
hardstatus alwayslastline “%D-%M-%Y %c”
[…] References:Keeping SSH Sessions Alive […]
Hey Scott, thanks for the tip. This was really annoying!!!!
Hi guys I would like to have all ssh connections time out after 5 minutes of inactive connection
Triniboy: see Jack’s comment (number 11).
Scott (and Carthik): thanks for the tip, this was exactly what I needed!
Hey, thx for info! I was scanning through manpage and dind’t notice the option right a way.
Here’s the commanline I use:
# ssh -o ServerAliveInterval=10
sets 10 sec keep-alive-ping interval for this particular connection.
Awesome! Thanks for the tip.
very very usefull tip, thanks!
Is there any way to specify a idle/timeout setting when initiating the ssh client session to the remote server? I would like to not modify the default behavior of SSH, just a single instance from time to time. If possible, please post here would be a nice addition.
sikiş,
Look into this command:
ssh -o TCPKeepAlive user@host
I’m not sure what the defaults are when using it but it’ll basically do the same thing as mentioned in this post.
Thank you for the opportunity you gave
[…] The Ubuntu Blog has a nice lil’ article about keeping SSH sessions alive. […]
[…] vía Posted by rubensa Filed in GNU/Linux, Recetas Leave a Comment » […]
This works for sshfs and sftp and ssh port forwarding as well
[…] this tip is for a Linux client (found here –> Link); from February of 2006 it’s still pertinent today and what tipped me off to where I might […]
ayın yıldız filmi
Hey remove this porn link crap!!! Post #32 is bullshit spam porn link!!!
The point of dropping the connection is a security one, though. I let mine time out after idling for that reason. Just sayin’.
airtonix: apt-get install screen
[…] https://embraceubuntu.com/2006/02/03/keeping-ssh-sessions-alive/ This entry was posted in Linux. Bookmark the permalink. Post a comment or leave a trackback: […]
evden eve But I believe that resolves a few questions for me personally. Anyone else agree?This works for sshfs and sftp and ssh port forwarding as well ankara
[…] used exactly as stated in ssh’s manpages. Last, I had a problem with the SSH session dying, possibly due to lack of activity as in this article. I used the ‘-o ServerAliveInterval=’ command line option and that seemed to make it […]
Tip: when the session does freeze, hit enter, followed by tilde (~), followed by a dot (.). That doesn’t resume the session though.
[…] workflow has a lot of 5 minute breaks from SSH, too. After some searching the ‘net, I found a reference to setup SSH so that it transmits a keepalive packet to keep my connection alive. That got me […]
eskişehir satılık evler uygun fiyata satılık ev ilanları.
Do you publish anything witout first seeing what is written in it? 🙂 Do not do it or there will be always kinds of ads here.
By the way, I am thankful for the tip. It had been 11 minutes idle and I checked still the session is up. It should have gone so far without this fix (I used 180 secs).
Put this in a script on the server then add the script to ~/.bashrc with & to run in background:
while true
do
echo -en “\x0”
sleep 60
done
I have the same problem.ergo baby carrier sale
nice informative tips for me thanks
İYİ
run ‘top’ when you are done with your window! Problem solved. You can keep an eye on the box too with that.
teşekürler bilgi için elinize sağlık
antalya ev ilaçlama
hello and thank you…
fyi this works great for Krusader on Ubuntu Natty.
[…] workflow has a lot of 5 minute breaks from SSH, too. After some searching the ‘net, I found a reference to setup SSH so that it transmits a keepalive packet to keep my connection alive. That got me […]
I do not even know how I ended up here, but I thought this post was great.
I don’t know who you are but certainly you are going to a famous blogger if you aren’t already 😉
Cheers!
Great blog here! Additionally your web site a lot up fast!
What web host are you the usage of? Can I am getting your affiliate link on your host?
I desire my web site loaded up as fast as yours lol
if you are looking to acquire a remarkable, nice and interesting oreo 5s…you’ve noticed all of them! the actual typical sparkely oreo 5s work best! when we look at you these guys discontinue and also look! avoid surely enjoy they relating to the oreo 5s and value!! they may so excellent produce into the shopping area, the evening meal or wherever you will amagine!
I really like it when people come together and share views.
Great site, stick with it!
I blog quite often and I seriously thank you for your content.
This great article has really peaked my interest. I will book mark your website and keep checking for new details about once a week.
I subscribed to your Feed too.
Hey just wanted to give you a quick heads up and let you know a
few of the images aren’t loading correctly. I’m not sure why
but I think its a linking issue. I’ve tried it in two different web
browsers and both show the same results.
Hi mates, how is all, and what you would like to say regarding this article, in my
view its truly awesome in support of me.
If you locate that your scale is increasing in numbers, don’t forhet that you just mmay be losing
fat while gaining muscle.
Je νoudrai vus dire qque c’est vraiment une joie de vous lire
This piece of writing presents clear idea designed for the new viewers of blogging, that truly how to do blogging.
Magnifique ρoste une foiѕ de plus
[…] There is an example of configuring it here: https://embraceubuntu.com/2006/02/03/keeping-ssh-sessions-alive/ […]
I see you don’t monetize your website, don’t waste your traffic, you can earn additional bucks every
month because you’ve got hi quality content. If you want to know how to make extra bucks, search for:
best adsense alternative Wrastain’s tools
Depending on your hardware and software configuration, you may experience SSH connectivity issues. For example, some types of firewalls may preemptively close connections after a certain amount of time has elapsed.http://www.emlakzone.com
Most of what you say happens to be astonishingly precise and that makes me ponder the reason why I hadn’t looked at this with this light previously. This particular piece truly did switch the light on for me personally as far as this subject matter goes. Nevertheless at this time there is just one issue I am not too comfortable with and while I attempt to reconcile that with the core theme of your position, permit me observe what all the rest of the readers have to point out.Very well done.