shellsshserverterminalmosh

Using Mosh instead of SSH


I've been using ssh for the longest time but now I want to try mosh but the documentation isn't the strongest.

How would I write this ssh command using the mosh command in terminal??

ssh abc123@spaf.cs.utsa.edu -p 211 

Solution

  • Here's the straight-forward answer from the mosh documentation

    mosh --ssh="ssh -p 211" abc123@spaf.cs.utsa.edu
    

    For this to work, you still need to get mosh set up including having mosh on the target host and listening on a port (by default in the 60000 to 61000 range) that is cleared for a UDP connection in the target host firewall settings.

    See the "How it works" section of the README.md on github https://github.com/mobile-shell/mosh

    The mosh program will SSH to user@host to establish the connection. SSH may prompt the user for a password or use public-key authentication to log in.

    From this point, mosh runs the mosh-server process (as the user) on the server machine. The server process listens on a high UDP port and sends its port number and an AES-128 secret key back to the client over SSH. The SSH connection is then shut down and the terminal session begins over UDP.

    If the client changes IP addresses, the server will begin sending to the client on the new IP address within a few seconds.

    To function, Mosh requires UDP datagrams to be passed between client and server. By default, mosh uses a port number between 60000 and 61000, but the user can select a particular port with the -p option. Please note that the -p option has no effect on the port used by SSH.

    What does that mean that the -p option has no effect on the port used by SSH? That refers to the mosh option, not the SSH option. So in other words, what you want and what I gave you above basically says: "Use port 211 to establish a connection via SSH and then, once it's all set up, use a default port for mosh in the 60000-61000 range" (assuming you have a default setup).

    If, on the other hand, you were to us the mosh -p option like so

    mosh -p 211 abc123@spaf.cs.utsa.edu
    

    This is absolutely not going to work, because that would be telling mosh to try to connect over the port reserved for SSH, which will fail, and furthermore, it will default to trying to establish the connection via the standard SSH port 22, which will also fail. In other words, the above says: "Use SSH on port 22 to connect to the mosh server listening on port 211." Since all those things are false in your case, it doesn't work.

    So in addition to specifying your particular SSH port, you need to also make sure that you have mosh running on the target host and listening either on the default ports or on another port you specify. You also have to make sure your firewall rules are set up to allow that connection.