mosh - mobile shell

安装

Ubuntu

$ sudo apt install mosh

MacOS

$ brew install mosh

用法一

和使用 ssh 一样,ssh 怎么用,mosh 就怎么用。

$ mosh user@server_addr

locale 语言和编码配置不正确时可能出现无法连接的情况,完成 locale 设置即可。

可能出现如下错误:

The locale requested by LC_CTYPE=zh_CN.UTF-8 isn't available here.
Running `locale-gen zh_CN.UTF-8' may be necessary.

The locale requested by LC_CTYPE=zh_CN.UTF-8 isn't available here.
Running `locale-gen zh_CN.UTF-8' may be necessary.

mosh-server needs a UTF-8 native locale to run.

Unfortunately, the local environment (LC_CTYPE=zh_CN.UTF-8) specifies
the character set "US-ASCII",

The client-supplied environment (LC_CTYPE=zh_CN.UTF-8) specifies
the character set "US-ASCII".

locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=zh_CN.UTF-8
LANGUAGE=
LC_CTYPE=zh_CN.UTF-8
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
Connection to xxx.xxx closed.
/usr/local/bin/mosh: Did not find mosh server startup message. (Have you installed mosh on your server?)

可以在服务端执行配置:

$ sudo locale-gen zh_CN.UTF-8

用法二

通过 udp 指定端口建立连接

服务端

$ mosh-server

MOSH CONNECT 60001 I/mC5i8Fs6v9ekiMzhw0Lp

mosh-server (mosh 1.3.2) [build mosh 1.3.2]
Copyright 2012 Keith Winstein <mosh-devel@mit.edu>
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

[mosh-server detached, pid = 2143]

I/mC5i8Fs6v9ekiMzhw0Lp 为临时密钥,60001 为端口号。

客户端

$ MOSH_KEY=I/mC5i8Fs6v9ekiMzhw0Lp mosh-client 107.174.107.174 60001