Mosh(mobile shell)是一款基於UDP的遠端終端軟體,包含客戶端和伺服器兩部分,用於代替SSH。因為Mosh基於UDP,所以它可以提供不間斷的連線,非常適用於在網路狀況不好或時延較大的網路中進行遠端終端訪問。比如,在GPRS或3G行動網路訪問遠端伺服器,或者從國內訪問國外伺服器等特殊場景。
以下是Mosh官網給出的簡介:
Mosh (mobile shell)
Remote terminal application that allows
roaming
, supports
intermittent connectivity
, and provides intelligent
local echo
and line editing of user keystrokes。Mosh is a replacement for SSH。 It‘s more robust and responsive, especially over Wi-Fi, cellular, and long-distance links。Mosh is free software, available for GNU/Linux, BSD, macOS, Solaris, Android, Chrome, and iOS。
本文給出一個基於CentOS的遠端Mosh客戶端訪問伺服器的例項作為參考:
1。 伺服器
本例伺服器環境:CentOS 7。3
在伺服器上安裝:yum install mosh
在伺服器上執行:
mosh-server
執行後將顯示:MOSH CONNECT
60001 PoLSHfJxwzQ7EcxgdIcmvA
其中
60001
為mosh-server伺服器監聽的UDP埠號;
其中
PoLSHfJxwzQ7EcxgdIcmvA
為mosh-server為客戶端分配的臨時KEY。
還需要確保iptables允許UDP
60001
埠的連線接入,如果不關心安全性可用iptables -F清空所有iptables配置,如果關心安全性可用iptables -I INPUT -p UDP ——dport
60001
-j ACCEPT以允許UDP
60001
埠接入。
另外,伺服器的IP地址為
10。1。2。3
。
2。客戶端
本例客戶端環境:CentOS 7。3
在客戶端上安裝:yum install mosh
在客戶端上執行:
MOSH_KEY=
PoLSHfJxwzQ7EcxgdIcmvA
mosh-client
10。1。2。3
60001
即可連線到mosh伺服器
10。1。2。3
:
60001
。
附:mosh用法
# mosh
Usage: /usr/bin/mosh [options] [——] [user@]host [command。。。]
——client=PATH mosh client on local machine
(default: “mosh-client”)
——server=COMMAND mosh server on remote machine
(default: “mosh-server”)
——predict=adaptive local echo for slower links [default]
-a ——predict=always use local echo even on fast links
-n ——predict=never never use local echo
——predict=experimental aggressively echo even when incorrect
-4 ——family=inet use IPv4 only
-6 ——family=inet6 use IPv6 only
——family=auto autodetect network type for single-family hosts only
——family=all try all network types
——family=prefer-inet use all network types, but try IPv4 first [default]
——family=prefer-inet6 use all network types, but try IPv6 first
-p PORT[:PORT2]
——port=PORT[:PORT2] server-side UDP port or range
(No effect on server-side SSH port)
——bind-server={ssh|any|IP} ask the server to reply from an IP address
(default: “ssh”)
——ssh=COMMAND ssh command to run when setting up session
(example: “ssh -p 2222”)
(default: “ssh”)
——no-ssh-pty do not allocate a pseudo tty on ssh connection
——no-init do not send terminal initialization string
——local run mosh-server locally without using ssh
——experimental-remote-ip=(local|remote|proxy) select the method for
discovering the remote IP address to use for mosh
(default: “proxy”)
——help this message
——version version and copyright information
Please report bugs to mosh-devel@mit。edu。
Mosh home page: the mobile shell
Reference:
0。
老宋的獨家號
1。
the mobile shell
注:本文為老宋原創文章,轉載前請至【知乎專欄-老宋的獨家號】點贊或評論建議。