mosh在不同平台上的安装和使用方法
本文详细介绍mosh在 mac os x 和linux(以CentOS、ubuntu为代表)上的安装和使用方法。
mosh在不同平台上的安装方法:
1、Mac os X上的安装
brew install mosh
2、centos上的安装
yum install mosh -y
3、ubuntu上的安装
$ sudo apt-get install python-software-properties
$ sudo add-apt-repository ppa:keithw/mosh
$ sudo apt-get update
$ sudo apt-get install mosh
4、tar包安装
下载地址:http://mosh.mit.edu/mosh-1.2.4.tar.gz
$ cd mosh-1.2.4
$ ./configure
$ make
# make install
依赖包:
- Name Typical package
- Protocol Buffers protobuf-compiler, libprotobuf-dev
- ncurses libncurses5-dev
- zlib zlib1g-dev
- utempter (optional) libutempter-dev
- OpenSSL libssl-dev
三、mosh的使用方法
1、 指定开启的端口 使用-p选项
mosh使用的UDP协议连接的,使用的端口是从60000到61000
Mosh will log the user in via SSH, then start a connection on a UDP port between 60000 and 61000.
因为 Mosh 使用的是 UDP 端口,所以服务器上需要打开某 UDP 端口。
假设 Mosh 使用 60001 UDP 端口,则在服务器上运行:
$ sudo iptables -I INPUT -p udp --dport 60001 -j ACCEPT
这样就在服务器上打开 60001 UDP 端口。当然,最好是把上一条命令写入服务器 firewall 的规则中,这样不必要每次都手动打开这个端口。
客户端进行连接时指定端口并开启端口,默认端口从60001开始开启。
接下来就是从客户端连接:
如下,如果原来连接服务器是采用密码的方式登录,会提示输入密码,如果ssh已经做好了密钥认证,则可以直接连接
$ mosh -p 60001 用户名@ip地址
p 参数用于指定 UDP 端口。
假如你的 SSH 连接 设置公钥/私钥连接,比如 ssh zfanw 即可直接连接服务器而无需输入密码,则 mosh 命令也可以以mosh zfanw 的形式连接,基本上,可以把它当作 ssh 命令的替换,只不过 ssh 开的是 TCP 口,mosh 开的是 UDP 口。
2、指定服务端ssh开启的端口,如下面所示:
假设服务端开始的端口是2222
$ mosh --ssh="ssh -p 2222" 用户@服务器IP
3、如果私钥不在默认的目录
$ mosh --ssh="~/bin/ssh -i ./identity" 用户@服务器IP
效果如何?开两个窗口,一个直接 ssh 登录,一个通过 mosh 登录,对比输入一下就知道了 – 当然是 mosh 的输入流畅。
Mosh 有很多强于 ssh 的特性,比如连接不会掉,你可以盖上笔记本电脑让它休眠,然后再打开,mosh 的连接还在,而如果是 ssh 的话,直接就断掉。