mosh - 一款替代SSH的UDP远程终端软件

mosh - 一款替代SSH的UDP远程终端软件

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

注:本文为老宋原创文章,转载前请至【知乎专栏-老宋的独家号】点赞或评论建议。

编辑于 2018-06-24 11:59