Jump to content

Ssh Connection Drops


george

Recommended Posts

I use SSH daily to a remote Linux server. The bad internet recently makes my SSH connection to drop, and I have to reconnect and login again. All manually as there is no re-login script provided.

Any ideas what I can do?

I am using Putty in Windows 7, but ask here in the Linux forum.

Link to comment
Share on other sites

Set keepalive on, usually if you don't do anything for a minute orso the connection drops because the intermediate (NATing) routers forget about your connection.

In Putty:

Load your session,

on the left hand side, click on 'connection'

check: enable TCP keepalives

put 30 in seconds between keepalives

Save your session.

Also, putty can auto-logon, but you have to generate a keypair with puttygen.exe (seperate download) and put the public one on the server in your home directory (/home/{user}/.ssh/authorized_keys file)

Good luck,

JD

Link to comment
Share on other sites

What is it about the disconnect which annoys you? If its losing what you were doing- simply include a new hop in the route- so ssh to one server, then use that server to ssh to the one you're working. This will allow things to continue even if your own connection drops. Additionally you can usee && at the end of your commands, to allow things to run in the background. SSH is typically very hard to drop so your connection must be really suffering. If your connection doesnt drop entirely but your ssh keeps dropping, you might want to try a different port.

Edited by OxfordWill
Link to comment
Share on other sites

also use 'screen' (man screen), basically saves your terminal session in between connects. just type 'screen' in linux the first time you connect, then when you get disconnected, next time 'screen -r' restores the screen from where you left.

Commands that were running don't get interrupted by your disconnect.

You can use ctrl-a, d to manually detach if you want.

more options in 'man screen'

use it, you'll love it.

Link to comment
Share on other sites

Use screen like the other poster said. It's the guru shell way to keep your processes from being SIG TERM'd or SIG KILL'd when your ssh session drops.

Another neat way is nohup <process> &

this gives you a log of the program output in a file called noup.out and as the same suggests, it will ignore SIG HUP/TERM (but not KILL I think). 'man kill' 'man nohup'

ssh is TCP so isn't going to drop unless something ratshit is happening en-route. Oh, you're in Thailand right?

NAT mappings don't die unless the NAT router is likewise RS

Ignorant engineers (you are in Thailand right?) tend to demonstrate their lack of skill by messing around too much with things that should be set-and-forget. That's about the only cause I can think of for TCP sessions dropping (lost-in-trasit IP packets due to twonks fiddlefarting with BGP route anouncements being a case in point).

PS 'keepalive' just tells the other ssh process to, if it is configured to allow it, *drop the ssh connection* if keep-alives are not 'seen' at the regular interval. The purpose of a keep-alive is to stop you from being locked out of 'something' due to 'something' thinking you're still logged in (a 'bogus session')

Folks often take this term on face value thinking it will magically 'keep things alive'. It doesn't (but you can waste a tonne of valuable debug time thinking it does).

Link to comment
Share on other sites

PS 'keepalive' just tells the other ssh process to, if it is configured to allow it, *drop the ssh connection* if keep-alives are not 'seen' at the regular interval. The purpose of a keep-alive is to stop you from being locked out of 'something' due to 'something' thinking you're still logged in (a 'bogus session')

While this is obviously true, keepalive does doe one more thing, which is important in this context: when you are idle for a while it does send the occasional query packet.

Here our great network engineers have blessed us with private routing nets and cheap NATing routers all over the place. These things tend to be starved for memory, and can't cope with the thousands of connections running through them, so after a while they tend to 'forget' (actually make room for new connections) old 'inactive' connections.

Doesn't matter, because the 'interweb' only uses short-term connections anyways, right...

So by sending these keepalive packets starved or just misconfigured NATing routers tend not to forget your session so quickly. I have had a lot of success by using this option, while other people report lots of success by switching it off... :)

*J*

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.






×
×
  • Create New...