Tip for using mosh with the ssh add-on and tmux (Updated 2024-11-05)
To start a mosh session from the command line that will use tmux run:
mosh hassio@homeassistant -- sudo -i tmux a -t homeassistant
NOTE: this will share the tmux session with the web terminal.
Why is this necessary?
With the add-on, you ssh in as user hassio
(a non-root user). However, the add-on has a .profile
in /home/hassio
that runs sudo -i
to provide an interactive session running as root
inside of the add-on’s container.
Since a command is being run, rather than the default of starting an interactive shell, the profile doesn’t get evaluated. So the session is running as user hassio
with the wrong permissions and doesn’t /root/.zshrc
which gives the familiar prompt, Oh my Zsh features, etc.
NOTE: this is why other things that use ssh like rsync run into unexpected permissions issues. rsync winds up running as user hassio
and not root
as expected. Copying world readable files out works fine, but copying in files can fail unless permissions are changed.
original post
[Sorry if this info is already here but I can’t find it.]
Are there tips & tricks for using this add on with mosh and tmux? It mostly works, but:
* ~/.tmux.conf
doesn’t seem to get evaluated with using mosh, so the prefix key is still CTRL-B, instead of CTRL-A (or whatever I want to change it to, CTRL-)
* Creating new windows in tmux works as expected
If I manually source it using tmux -S /tmp/tmux-1000/default source-file ~/.tmux.conf
:
* I get the right prefix control
* I get the right tmux status line from ~/.tmux.conf
* the Zsh prompt in the first window is ok.
However, if I create a new window PREFIX + c
, the new window:
* Is created as uid=1000(hassio) gid=1000(hassio)
instead of uid=0(root) gid=0(root)
* $HOME is /home/hassio
instead of /root
* the Zsh prompt displays as \[\e]0;\u@\h:\w\a\]\W $
Edit: In case it matters, the way I start the mosh/tmux session is:
mosh hassio@hasshost -- tmux
(I’m running it inside of a Cygwin mintty window on Windows 11, using Cygwin’s mosh)
The problem doesn’t occur if I just use mosh to get a session, and then run tmux manually once logged in. Aside from the extra manual step, this also changes to the window title to [mosh] _zsh_tmux_plugin_run
and I can no longer change it.