Mosh

Install

在服务器端需要运行mosh-server,默认情况下使用 UDP 60001~61000 范围的端口简历session

查看端口是否监听成功

1
netstat -anp | grep mosh

Ubuntu 18.04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#sudo apt remove iptables
sudo apt-get update -y
sudo apt-get install -y mosh
# 为了防止出现乱码,安装locales组件
# sudo apt-get install locales
# 添加对en_US.UTF-8的支持
#echo -n "export LC_ALL=en_US.UTF-8" >> ~/.bashrc
#echo -n "export LANG=en_US.UTF-8" >> ~/.bashrc
#echo -n "export LANGUAGE==en_US.UTF-8" >> ~/.bashrc
# 写入locale配置文件,保存设置
# localedef -v -c -i en_US -f UTF-8 en_US.UTF-8
# iptables -I INPUT -p udp –dport 60001 -j ACCEPT
# 开启60000到61000的端口
# iptables -I INPUT -p udp –dport 60001:61000 -j ACCEPT

启动mosh服务器命令:

1
2
3
4
5
6
7
8
mosh-server &
# MOSH CONNECT 60001 6Gk54MYxcVOpkXv8/fgwPw
# 客户端使用连接命令如下:
# 1.export MOSH_KEY=6Gk54MYxcVOpkXv8
# 2.mosh-client host port

# add startup, crontab -e
# @reboot /usr/bin/mosh-server

MacOS

1
brew install mosh

配置locale

1
2
3
4
5
echo -n "export LC_ALL=en_US.UTF-8" >> ~/.bashrc
echo -n "export LANG=en_US.UTF-8" >> ~/.bashrc
echo -n "export LC_CTYPE=en_US.UTF-8" >> ~/.bashrc
echo -n "export LANGUAGE==en_US.UTF-8" >> ~/.bashrc
localedef -v -c -i en_US -f UTF-8 en_US.UTF-8

Usege

1
2
3
4
5
6
mosh root@host -p 60001

mosh -ssh="ssh -i ~/.ssh/id_rsa -p 10002" user@host
mosh -ssh="ssh -p 10002" user@host

MOSH_KEY= mosh-client host 60001