-
Notifications
You must be signed in to change notification settings - Fork 1
Using Mosh on the department systems
Mosh is a replacement for ssh(1)
. It's more robust and responsive, especially over Wi-Fi, cellular, and long-distance links as it supports intermittent connectivity and smoother client-side interaction.
Here's some example use-cases for Mosh, taken from their home page:
- Mosh automatically roams as you move between Internet connections. Use Wi-Fi on the train, Ethernet in a hotel, and LTE on a beach: you'll stay logged in.
- With Mosh, you can put your laptop to sleep and wake it up later, keeping your connection intact. If your Internet connection drops, Mosh will warn you — but the connection resumes when network service comes back.
- ...and more!
-
Set up OpenVPN on your local machine using the Brown CS instructions.
-
Connect to either the
<username>_browncs.ovpn
or<username>_browncs_gateall.ovpn
endpoints. Either one works for the purposes of usingmosh
;*_browncs.ovpn
will only route yourcs.brown.edu
traffic through the VPN as opposed to*_browncs_gateall.ovpn
which will route all traffic through the VPN. -
Connect to
mosh
using the following command, where<ssh-address>
is in the formUSERNAME@ssh.cs.brown.edu
(the public key endpoint,pk-ssh.cs.brown.edu
, also works):mosh --experimental-remote-ip=remote <ssh-address>
The
--experimental-remote-ip=remote
flag is needed as thessh.cs.brown.edu
server is an SSH forwarder, so you'll end up on a machine that will have a different IP address from that of thessh
endpoint.mosh
needs this flag in order to handle this forwarding mechanism. -
You're all set!
This section contains optional instructions for using mosh
for various operating systems. They are not required to use Mosh.
If you're using MacOS and are using Tunnelblick to connect to the OpenVPN server (as recommended by the Brown CS setup page), you can control Tunnelblick from the command-line using AppleScript. This can be helpful as you can then set up an alias that automatically connects to the Brown CS VPN when you try to run mosh
so you don't have to remember to turn it on manually beforehand.
-
Copy the two AppleScript files below to a location on your computer.
brown-tunnelblick-connect.scpt
connects your computer to thebrowncs
OpenVPN endpoint, andbrown-tunnelblick-disconnect.scpt
disconnects your computer from the VPN. Each script can run from the command-line with the following:osascript <path-to-script>
For the purposes of this tutorial, I'll assume these scripts are stored in the
~/scripts
directory. -
Write some aliases in your shell configuration file (ex:
.bashrc
) to automatically start Tunnelblick when you want to runmosh
:alias vpn-connect="osascript ~/scripts/brown-tunnelblick-connect.scpt" alias vpn-disconnect="osascript ~/scripts/brown-tunnelblick-disconnect.scpt" alias brown-mosh="vpn-connect && mosh --experimental-remote-ip=remote <ssh-address> && vpn-disconnect"
Running the
brown-mosh
command will then start the VPN, runmosh
, then disconnect from the VPN whenmosh
exits. -
That's it!
This script will attempt to connect to the <username>_browncs
endpoint if your computer is not currently connected to the VPN:
set vpnConfig to "<username>_browncs"
tell application "/Applications/Tunnelblick.app"
set vpnState to (get state of first configuration where name = vpnConfig)
if vpnState = "Exiting" then -- "Exiting" means that it's not currently connected
connect vpnConfig
end if
end tell
This script will disconnect your computer from the <username>_browncs
endpoint if you're currently connected to it:
tell application "/Applications/Tunnelblick.app"
disconnect "<username>_browncs"
end tell