24

I am dealing with a really slow shell connection. It is in the cloud and I am very far from the server. My connection also breaks sometimes as it is over the internet and I may also be using shared Wifi or 3G. Is there a way to see what I type instantly? Trying to type commands and waiting for each character is atrocious.

Zombies
  • 495
  • 2
  • 5
  • 13

4 Answers4

26

Try Mosh.

Mosh (mobile shell)
Remote terminal application that allows roaming, supports intermittent connectivity, and provides intelligent local echo and line editing of user keystrokes.

Mosh is a replacement for SSH. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links.

Mosh is free software, available for GNU/Linux, FreeBSD, Solaris, Mac OS X, and Android.

dmourati
  • 24,720
  • 2
  • 40
  • 69
  • 3
    Caveats to mosh: (1) it's much more cpu intensive than ssh. (2) If your mosh session doesn't end normally, you'll have a leaked connection that can never be re-established. (I have to houseclean my shell box otherwise there will be dozens of processes running). – user606723 Dec 02 '13 at 18:44
  • Another issue is that it is near impossible to install on linux distro like Suse (SLES). I spent hours trying to install it as either an openSuse package or compiling it from source. – Zombies Dec 04 '13 at 02:20
  • $ sudo zypper in mosh (acording to the docs) – dmourati Dec 04 '13 at 05:28
  • Yes that will work fine on openSuse, but a corporate/closed distro it is very tasking to install new open source projects. – Zombies Dec 06 '13 at 09:03
  • NB it doesn't support scrollback (at all) so you basically have to run screen or tmux to get that. – rogerdpack Jan 25 '22 at 20:16
10

an alternative (and also in addition) to dmourati answer: use screen or tmux or other things, to keep sessions alive when you are disconnected. (You simply re-attach to the session after you reconnect, and see the terminal as you left it, even with full screen programs [vi, etc]). It also have many other benefits (sharing sessions with co-workers, etc) (as in Mosh own faq it states:

Q: Why is my terminal's scrollback buffer incomplete?

Mosh 1.2 synchronizes only the visible state of the terminal. Mosh 1.3 will have complete scrollback support; see this issue and the others which are linked from there. For now, the workaround is to use screen or tmux on the remote side.

And you should also use rsync to copy files, without having to re-send already sent parts over the network when the connection dies.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
Olivier Dulac
  • 1,202
  • 7
  • 14
  • Mosh 1.3 is out, but they haven't implemented scrollback https://github.com/mobile-shell/mosh/issues/122 you basically have to use screen or tmux underneath. – rogerdpack Jan 25 '22 at 20:16
2

You should see where the latency/bottleneck(s) are. You should try to get better access to infrastructure... either locally or at the provider's side. You wrap your important or critical sessions in tmux or screen multiplexers...

Please give us numbers. It takes a particularly-bad connection for simple SSH sessions to have problems... I've had to access systems on the other side of the world from an airplane over a VPN and still haven't had too much trouble. Is this a persistent issue? What does traceroute tell you?

ewwhite
  • 194,921
  • 91
  • 434
  • 799
  • The issue occurs on hotel wifi a lot, where there are too few routers and too many devices/laptops sharing internet access. Also shared hotel wifi is inherently pretty crummy with ping times as going through 1 or more walls really adds a lot of ms delay. That is also another major bottleneck. Similar situation occurs on 3G, where that much distance to the cell phone tower adds MS. When using SSH shells, I have to wait for each character. A MS of 200-400 can be pretty annoying, but with spikes of up to 1 second... ouch. – Zombies Dec 04 '13 at 02:18
2

For future readers of this thread, @lowellheddings' tip in his blog, together with the use of screen, could help overcome this issue:

You can configure the ssh client to automatically send a protocol no-op code code every number of seconds so that the server won’t disconnect you. This setting is sometimes referred to as Keep-Alive or Stop-Disconnecting-So-Much in other clients.
Add the following line to the /etc/ssh/ssh_config file:
ServerAliveInterval 60
...

  • I've done this both on client and server (ClientAliveInterval) and disabled TCPKeepAlive, but it still drops with `client_loop: send disconnect: Broken pipe`. Any clue? – M. Volf Mar 11 '21 at 21:32
  • @M.Volf broken pipe means the remote end (or a firewall in between?) decided to close the connection, so the send is now impossible (and the "pipe" between client and server is broken). `ssh -o ServerAliveInterval=60 user@host` will try to keep the connection alive by sending a "nop" packet every 60 seconds – Olivier Dulac Feb 01 '22 at 15:41