Skip to main content
dcyfr.codes
beginnerbash

Mosh + Tailscale Connection Script

Connect to a remote host via Mosh over Tailscale with a static UDP port for firewall compatibility.

Code

#!/usr/bin/env bash
# Connect to remote workbench via Mosh over Tailscale
# Usage: ./mosh-connect.sh [tailscale-hostname]

HOST="${1:-workbench}"
MOSH_SERVER="$(which mosh-server 2>/dev/null || echo '/usr/local/bin/mosh-server')"

mosh \
  --server="$MOSH_SERVER" \
  --port=60001 \
  --predict=adaptive \
  "$HOST" \
  -- tmux new-session -A -s main

How it works

Use `--port` to pin Mosh to a single UDP port (60001) so only one firewall rule is needed. `tmux new-session -A -s main` attaches to an existing session if one exists, creating a new one otherwise — perfect for resume-on-reconnect workflows.