0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Mosh:一款替代SSH的远程登录软件

Posted at

Mosh是什么

Mosh表示移动Shell(Mobile Shell),可以说是 SSH 的 mobile 版本。
Mosh最大的特点是基于UDP方式传输,支持在服务端创建一个临时的Key供客户端一次性连接,退出后失效;也支持通过SSH的配置进行认证,但数据传输本身还是自身的UDP方式。

SSH的问题

SSH 作为一个远程访问协议,在提出时是为了解决 telnet 的安全性。在 20 多年后(SSH 在 1995 年由 Tatu Ylönen 提出),它已经成为了远程shell 访问的事实标准。

SSH 采用了 TCP, TCP 在 SSH 设计之初是最好的选择。TCP 提供的特性(面向连接、可靠)简直就像量身定制。但是在现在,这种面向连接的设计却不够灵活了:TCP 的有状态连接使得设备在切换网络,或连接因其他原因断开的时候,就会丢失整个 session 无法恢复。

Mosh 要解决什么问题

  • 解决漫游时连接中断问题。当然不仅仅是漫游的问题,还有电脑休眠、无线网闪断等情况。以前的方式是使用 screen 或 tmux。

  • 解决了回显慢的问题。这一点尤为重要。一般的 term 所有输入和输出都需要与远程服务器交互,甚至每次敲击键盘的回显也是由远端的 shell 进程控制。mosh 客户端使用代理,对大部分可以预测的回显,直接在本地完成。这一改进意味着以后登陆一个网络很大的服务器,输入命令时不再等待每个字符回显,而可以一口气写下来,由 mosh 去同步命令。

  • ......

使用

服务端:

mosh-server -p 3000 #启动 3000 端口

#MOSH CONNECT 3000 PoLSHfJxwzQ7EcxgdIcmvA

客户端:

MOSH_KEY=PoLSHfJxwzQ7EcxgdIcmvA mosh-client 1.1.1.1 3000

参考:

https://zhuanlan.zhihu.com/p/28414523
https://www.hi-linux.com/posts/23118.html
https://blog.yangl1996.com/post/mosh-the-ssh-replacement/
https://my.oschina.net/hao7234/blog/358217
https://github.com/mobile-shell/mosh/issues/1039

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?