Since I have moved to Germany, the server on Aliyun is going to very hard to control and even type some command will get a delay because of the 'Wall' between China mainland and outside. Before I didn't spend too much time on the Alinyun server side, it's not serious. But since I start to maintain my own Wechat official account, then a new tool which can fix this issue becomes too significant.
After a little search, I found 'Mosh'. The purpose for mosh is a replacement for interactive SSH terminals. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links. And mosh means mobile shell.
Today I will introduce mosh a little bit.
First of all, you need a server which is support mosh. I assume we using Ubuntu 16.04 as the server.
It's very easy to install on Ubuntu,
apt-get install mosh to get the latest version. FYI, current on my server side the mosh version is 1.2.5.
This link is the official Mosh website, you can find all different System install package here.
And you can setup your sshd configuration as usual for change the port, password required... And mosh also support ssh-config like under Mac OS. So set up as normal.
Open for firewall
Mosh is using UDP port 60000 ~ 61000 as the connection port. So please make sure it can pass through your firewall on the server side.
If you are using iptables directly, the following command will open the ports that Mosh requires:
sudo iptables -I INPUT 1 -p udp --dport 60000:61000 -j ACCEPT
Remember that, by default, this firewall setting will not be retained after a system reboot. Solutions such as iptables-persistant exist to augment this behavior.
If you are using UFW, you can open the ports with the following:
sudo ufw allow 60000:61000/udp
Or controlled by AWS or Alinyun security role, please go to the console to add it manually. By adding new role which is support 60000/61000 and allowed the IP address 0.0.0.0/0 for Type UDP.
After preparing the server side, on the client you just need to install the mosh-client is enough. If you are using HomeBrew, just need to run
brew install mosh, it will prepare the CLI for you.
How to use?
For example, before when you are using SSH directly like
ssh ubuntu@<IP address> -p <port> -i <ssh key> then to
mosh ubuntu@<IP address> --ssh="ssh -p <port> -i <ssh key>".
The command is a little bit tricky, but don't worry. If you are using ssh config under .ssh/config, you can directly switch from
ssh 31mins to
mosh 31mins. It's quite easy and no need other changes.
The feeling of using Mosh is much better than running on the directly SSH.
Sometimes, DevOps also need to do something urgent with mobile now. And there is a very good terminal on iOS named Blink Shell. And they also provide the source code on Github for Developer who can directly compile and install on the phone.
By following the instruction to download the source code and execute the
./get_frameworks.sh. After preparing the code, you can directly open the Xcode project. The only missing from this project is you need to go to Capabilities->iCloud-> To create a new iCloud container with your own project Bundle identifier. And you are able to build and run on your phone.
There are some tricks for the command line. Run
config to set up your host and keys. Then you are able to use mosh on your phone.
Also, Termius is a very good terminal as an alternative choice. It also supports mosh.