Is there a way to use mosh without giving up the local scrollback?

Basically, in some circumstances, IP-roaming is indeed useful and needed, but the extra terminal emulation and key prediction seems to only be getting rid of the local scrollback buffer lines and the session history.


4 Answers 4


Filippo Valsorda has a solution for OS X that incorporates iTerm 2, tmux, and mosh.

His solution uses a single window/tab to connect to a remote shell. The shell survives disconnects (e.g., connection failure, IP changes, laptop reboots) and supports scrollback with a touchpad, copy-paste, and colors.

Caveats are that you must build mosh from source, scrolling is less fluid than native, and click-drag is relayed, so you must hold Option to select.

  • iTerm

    In the Terminal Profile settings, Enable xterm mouse reporting and set Report Terminal Type to xterm-256color.

  • tmux

    Set ~/.tmux.conf on the server to the following. With these settings, if you try to attach and there are no sessions, a new one is created. The settings also enable mouse interactions (and thus touchpad scrolling).

    set-window-option -g mode-mouse on
    set -g history-limit 30000

    Note: On more recent tmux (i.e. > 2.1), as reported by tmux -V, the various mouse options (mouse-resize-pane, mouse-mode, etc.) have been rewritten to a single option mouse, so you have to change the second line above to set-window-option -gmouseon instead.

    This mouse scroll will also work when you are in keyboard scroll mode (e.g. Ctrl-b then [), described in the article How to scroll in tmux.

  • mosh

    The stable build of mosh is old and does not support mouse reporting (and touchpad scrolling). To install the latest version, do the following:

    OS X (your client)

    brew install --HEAD mobile-shell

    Linux/UNIX (the server)

    git clone https://github.com/keithw/mosh.git
    cd mosh/
    sudo apt-get build-dep mosh
    ./autogen.sh && ./configure && make
    sudo make install

Now, to connect, just type the following:

mosh HOST -- tmux a
  • 7
    It's considered good form to paste the important information from the link in-line.
    – HalosGhost
    Oct 13, 2014 at 20:05
  • 2
    though this answer was downvoted for technical reasons, it's probably the best (only?) way to get decent scrollback on the local client using mosh.
    – jayhendren
    Oct 13, 2014 at 20:26
  • 1
    @jayhendren: or you can simply use Eternal Terminal. Jul 21, 2019 at 19:39
  • 1
    No need to be condescending. My comment was from 2014. The first release of Eternal Terminal was in 2017.
    – jayhendren
    Jul 21, 2019 at 23:21
  • 1
    2019 and the solution still works
    – user913
    Oct 30, 2019 at 11:23

The terminal emulation is baked pretty deep into the design of mosh, so, no. Mosh works by having both client and server each maintain its local idea of what the screen currently "looks like", and that requires that the server does terminal emulation. This is how the client is able to refresh the contents of the screen after it has been away for a while and lost some data.

I think that an application with the IP roaming feature of mosh but without terminal emulation would end up being quite a different (but simpler) application. For such an application, loss of data (including when the client is off-net for some time) would result in loss or corruption of screen contents. This is an acceptable limitation if the user is using an application where this doesn't matter much (e.g. shell) or an application which has a repaint feature (e.g. vi using Control-L).

The implementors of Mosh are planning scrollback support in the application though, to make up for the fact that your local terminal cannot do it anymore. I guess this would have to work a little bit like screen's scrollback buffer though: controlled by keystrokes, not scrollbar and mouse.

  • I think you linked the wrong issue. This comment suggests that lack of scrollback is a separate report, which I think is this one
    – Hi-Angel
    Nov 6, 2020 at 11:28

Eternal Terminal ( https://mistertea.github.io/EternalTerminal/ ) is an alternative to Mosh that supports native scrollback and still allows IP roaming. ET doesn't do the typing prediction, so it may not be suitable if you have a high latency connection (if you are ssh-ing into a drone or from a cell phone), but personally ET does everything I want and supports scrollback.

  • that was awesome
    – Soorena
    Feb 4, 2018 at 12:31
  • ET is amazing and needs a lot more advocacy. Jul 21, 2019 at 19:38
  • I couldn't find a tutorial to how to use ET
    – alper
    Aug 27, 2020 at 15:23
  • Does ET support slow/flakey connections by only refreshing the viewable?
    – rogerdpack
    Jan 25, 2022 at 20:18
  • @alper it's right in the website and github. Basically just replace ssh with et unless you have some options to set
    – phuclv
    Mar 19, 2022 at 4:31

Unchecking "Scroll alternate screen" in Terminal->Preferences->Profiles->Keyboard fixed it for me.

  • 4
    this answer makes no sense, where do you even get such a menu?
    – cnst
    Aug 24, 2015 at 20:30
  • 4
    That prefs setting exists, but unchecking it caused scrolling to work only in my local window, ie scrolling down brought into view the lines that were there before i used the mosh command. it did not show me anything which had scrolled off the top of the remote session.
    – mARK
    Sep 9, 2015 at 1:24
  • 3
    Tried this, but it does not allow you to scroll in the mosh session
    – magodiez
    Feb 24, 2016 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .