Strovent SystemsSign in
Reference

Does Mosh read ~/.ssh/config? Host aliases, ports, --ssh and Dropbear

Mosh logs in with ssh, so ~/.ssh/config applies to that step: host aliases, users, ports and keys. What -p changes, how --ssh works, and Dropbear.

Mosh does not log in by itself. The mosh command runs ssh to log in to the host and start mosh-server, then closes that SSH connection and talks to the server over UDP. So the question "does Mosh read my SSH config?" has two answers: the login step uses everything ssh uses, and the UDP session that follows does not.

What ~/.ssh/config controls

Because mosh runs your normal ssh, a Host block in ~/.ssh/config works with Mosh as it does with SSH:

Host build
    HostName build01.example.com
    User fred
    Port 2222
    IdentityFile ~/.ssh/id_ed25519_build

mosh build then logs in as fred on port 2222 with that key. The same goes for ProxyJump and the other client options, but see Can Mosh go through a jump host or bastion? for what happens to the UDP part.

The Mosh manual says its default way of finding the server's address (--experimental-remote-ip=proxy) is "generally the most compatible with hosts and other options configured in ssh configuration files". The local method resolves the name on the command line itself and ignores ssh_config for that name.

Ports: two different ones

  • The SSH port is set the SSH way: Port in ~/.ssh/config, or --ssh="ssh -p 2222" on the command line.
  • The UDP port is Mosh's own: -p 60001 or a range such as -p 60000:60010. The manual notes that this option does not affect the server-side port used by SSH. Without it, Mosh picks a port from 60000 to 61000. See Mosh "Nothing received from server on UDP port 60001".

Changing the ssh command: --ssh

--ssh=COMMAND replaces the plain ssh that Mosh runs. Use it to add options for one connection:

mosh --ssh="ssh -p 2222 -i ~/.ssh/other_key" fred@host

For a host you use often, a Host block is simpler and works for ssh, scp and sftp too.

Dropbear or another SSH client

The manual describes --ssh as the OpenSSH command, and says the default proxy address method only works with OpenSSH. If the ssh on your computer is another client, such as Dropbear's dbclient, use the remote method, which reads the server's SSH_CONNECTION variable instead:

mosh --experimental-remote-ip=remote fred@host

Mosh still passes its own options to the ssh command, and whether another client accepts them depends on that client, so test it first. Options named --experimental-* may also change in later Mosh versions.

Settings Mosh takes from elsewhere

  • The server program: --server= sets the command run on the host, for example --server=/home/fred/bin/mosh-server when it is installed in your home directory. The manual notes that the server helper is unprivileged and can be installed there.
  • Prediction and the escape key: the MOSH_PREDICTION_DISPLAY and MOSH_ESCAPE_KEY environment variables set these for every session started on your computer.

-p, --ssh, --server and --experimental-remote-ip are options of the mosh command on a computer. This app's Mosh connection has no settings for them.

Sources

Spotted a mistake? Email [email protected].