# How to make SSH more tolerant of lag?

## Antimatter

I got a secure shell at SDF and my average ping is about 138 MS, and my ssh is sort of laggy, so I'm wondering if there isn't any tip/trick at making it more lag-tolerant or lag-resistant?

thanks!

----------

## turtles

could it be your router or a firewall somewhere?

You may be able to set the priority for ssh on the cpu on the server?

----------

## codergeek42

Would compressing the tunnel help? (`ssh -C ...`)

----------

## Antimatter

Problem is the server is out of my hand, its SDF.lodestar.org which is a shell server, and while their load and so forth aren't too bad, for some reason there is a huge spike in lag somewhere along my connection.

I did some trace-route research and i found that a New York connection got it as low as 30-50 Ms which isn't too bad, yet I'm in AZ which is close by, and my provider send and bounce me up and down the state of California a few time racking up the lag then finally bounce into Texas....

I'll take a look at compressing, it might help, let me give it a shot  :Smile: 

And i would love to set the priority on the server but that's out of my hand, and i think its router/firewall issue somewhere on Cox's network because its being bounced around many many time in California.

[edit]  Setting the -C seems to help its more responsive, and i also did a trace-route this morning and it seems that the lag is down to 90 Ms and under this morning.... hmmm...

----------

## Aurisor

Could you clarify a bit exactly what's bothering you about the lag?  Is the delay annoying you when typing?  If so, you might want to look into some kind of input buffering.  If it's disconnects, then that'd be more of a server thing.

By the way, you don't have any third ssh-capable machines, do you?  Sometimes I've had trouble routing to one particular host and defeated it by tunneling through one of my boxen in a different region.

----------

## Antimatter

 *ishan wrote:*   

> Could you clarify a bit exactly what's bothering you about the lag?  Is the delay annoying you when typing?  If so, you might want to look into some kind of input buffering.  If it's disconnects, then that'd be more of a server thing.
> 
> By the way, you don't have any third ssh-capable machines, do you?  Sometimes I've had trouble routing to one particular host and defeated it by tunneling through one of my boxen in a different region.

 

Sorry, what i mean by the lag, is that the delay is very annonying when i am typing, it can take up to a few seconds for the characters to show up one at a time on the screen, along with scrolling or reading text, can be a bit laggy.  But anyway about input buffering, how would i do this? I frankly have zero idea on the topic of input buffering, other than using it once or twice on my mobile phone, but that input buffering was built into the program.

So far i have three ssh-capable machine, one at work which i am trying to tunnel out, i can't use that one because i can't get in, so that one is sort of moot point.  Second ssh-capable machine is my computer at home but its only on when i am at home so its out of the question.  Which leaves only 2 ssh-capable machine, one is "catcher.no-ip.org" but i suspect its in europe so there is quite a bit of lag there, and second one is "sdf.lorestar.org" which is located in texas.  Other than that, those are the only two machines outside my work computer or home computer that are ssh-capable..... and the problem is both of them are kind of laggy from my location, but I should be going back to university this winter so hopfully being in that location will help alots with the lag issue.

But for now i think the buffering would be the best solution, so i can type in an command, then verify and send it off for execution.

----------

## Sarpy Sam

I'll second that ssh being very laggy is a hard issue to deal with.  I am on a satellite Internet connection and any ssh out causes unbearable lag when typing on a remote machine.  What's this input buffering idea?

----------

## Antimatter

 *Sarpy Sam wrote:*   

> I'll second that ssh being very laggy is a hard issue to deal with.  I am on a satellite Internet connection and any ssh out causes unbearable lag when typing on a remote machine.  What's this input buffering idea?

 

My parents has satellite intenet connection, that kind of knowledge would be handy for when I move their boxen over to linux.

----------

## Janne Pikkarainen

 *Sarpy Sam wrote:*   

> I'll second that ssh being very laggy is a hard issue to deal with.  I am on a satellite Internet connection and any ssh out causes unbearable lag when typing on a remote machine.  What's this input buffering idea?

 

I think it's not about any kind of buffering. The lag happens because your computer needs to know if the other end received the data you sent there. So  the conversation is roughly like "I sent you out characters c, a and t, did you receive them?" - "Oh, yes I did." and only after that your terminal window updates itself. For a fast typer ping times of couple of hundreds of milliseconds or more can feel really sluggish and slow. 

There isn't much what you can do to improve ping time, unless the bottleneck is something in the middle, in which case you might want to try another route to the remote end, as suggested earlier in this thread.

Some ISPs tend to transfer their data in bigger chunks, which is suitable for P2P and such activity, but for interactive connections like ssh it's a pain. It might or might not help to mangle the ToS (Type of Service) packets with iptables. You might try

```
iptables -A OUTPUT -j TOS -m state --state NEW,ESTABLISHED,RELATED -t mangle -p tcp --dport 22 --set-tos Minimize-Delay
```

but often it doesn't actually help.

----------

## Antimatter

But I've actually seen ssh program on cell phones, that will provide you with a buffer where you type in the full command, then click enter, and it will take care of sending it over the link to the other side, is this possiable with openSSH, or would it require some kind of alteration or what so not?

And thank you Janne Pikkarainen, that explaination makes sense  :Smile:  sadly, the ping is out of my hand, and the firewall scripts are out of my hand also, so there isn't exactly that much i can do about the ping time.

----------

## Janne Pikkarainen

 *Antimatter wrote:*   

> But I've actually seen ssh program on cell phones, that will provide you with a buffer where you type in the full command, then click enter, and it will take care of sending it over the link to the other side, is this possiable with openSSH, or would it require some kind of alteration or what so not?
> 
> 

 

Ahh. That kind of function is from the golden BBS days  :Smile:  Terminal programs used to have a line editor, which allowed you to edit current command line. The data was sent after Enter key was pressed. So it's not buffering and not up to OpenSSH - instead your terminal program should have that line editor functionality. I don't know if any terminal actually has that nowadays... but of course you can always type your line to some text editor and copypaste it from there to terminal.  :Wink: 

----------

