Mosh: Difference between revisions

imported>Ghuntley
mNo edit summary
m Fix typo in header
Tags: Mobile edit Mobile web edit Visual edit
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{expansion|Missing installation and configuration of both server and client.}}
[https://mosh.org/ Mosh] is an alternative SSH terminal. It has support for roaming, local echo and uses UDP for transport. It also aims to improve responsiveness on intermittent, and high latency connections.
 
See the [https://search.nixos.org/packages?show=mosh&query=mosh mosh Package] and [https://search.nixos.org/options?query=programs.mosh mosh Options]
 
== Installation ==
 
=== Client ===
 
Install the <code>[https://search.nixos.org/packages?show=mosh&query=mosh mosh]</code> package.
 
=== Server ===
 
Enable the <code>[https://search.nixos.org/options?query=programs.mosh programs.mosh]</code> module. You can simply add the following into your <code>/etc/nixos/configuration.nix</code>:
 
<syntaxhighlight lang=nix>
# Enable mosh, the ssh alternative when client has bad connection
# Opens UDP ports 60000 ... 61000
programs.mosh.enable = true;
</syntaxhighlight>
 
== Usage ==
 
With mosh installed on both the client and server, connect by running:
 
<syntaxhighlight lang=console>
$ mosh user@server
</syntaxhighlight>
 
Note that mosh uses SSH for authentication and initialization, so it will respect aliases and other options in <code>.ssh/config</code>. You can also specify SSH options using the <code>--ssh</code> argument. For example, to use port 1122 instead of 22, you can either use <code>Port 1122</code> in SSH config, or use mosh with the <code>--ssh</code> argument:
 
<syntaxhighlight lang=console>
$ mosh --ssh='ssh -p 1122' user@server
</syntaxhighlight>
 
More information is available at [https://mosh.org/#usage mosh.org] or using <code>[https://manpages.debian.org/bullseye/mosh/mosh.1.en.html man mosh]</code>


== Troubleshooting ==
== Troubleshooting ==
Line 9: Line 43:
* nix-shell failing with <code>Error in tempdir() using /run/user/1000/nix-shell.XXXXX</code>
* nix-shell failing with <code>Error in tempdir() using /run/user/1000/nix-shell.XXXXX</code>


This is caused by the way <code>mosh</code> handles logging-in to the system, the login is actually handled by a short <code>ssh</code> session, which ends immediately. <code>logind</code>, as it is used, closes the user's session and cleans up behind, since there is no loingering configured by default.
This is caused by the way <code>mosh</code> handles logging-in to the system, the login is actually handled by a short <code>ssh</code> session, which ends immediately. <code>logind</code>, as it is used, closes the user's session and cleans up behind, since there is no lingering configured by default.
 
To enable lingering use:


As a workaround, it is possible to set an alias in the user's shell wrapping <code>mosh-server</code> to keep the session around.<ref>[https://botbot.me/freenode/nixos/2017-12-20/?msg=94859441&page=1 #nixos 2017-12-20]</ref>
<syntaxhighlight lang=console>
$ loginctl enable-linger $USER
</syntaxhighlight>
 
Then reconnect with mosh. Note that lingering is enabled by default in NixOS >= 16.09.
 
As a workaround, it is also possible to set an alias in the user's shell on the server wrapping <code>mosh-server</code> to keep the session around.
<ref>[https://github.com/NixOS/nixpkgs/issues/29234 issue#29234]</ref>


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
alias mosh-server = "systemd-run --user --scope mosh-server"
alias mosh-server = "systemd-run --user --scope mosh-server"
</syntaxhighlight>
See also https://github.com/NixOS/nixpkgs/issues/3702#issue-40762878
=== The locale requested by LANG=*** isn't available here. ===
This error occurs when trying to connect to a linux server (non-NixOS distribution) on which mosh-server has been installed via nix. The easy solution is to set LOCALE_ARCHIVE to your OS locale-archive in your .profile or .zshenv:
<syntaxhighlight lang=bash>
export LOCALE_ARCHIVE=/usr/lib/locale/locale-archive
</syntaxhighlight>
</syntaxhighlight>


Line 20: Line 73:
== References ==
== References ==
<references />
<references />
[[Category:Applications]]