Keep an SSH Localhost Tunnel Alive on Mac with autossh
Laptop sleep kills SSH. Your “API mysteriously died” is often just a dead tunnel. Here is a minimal keep-alive setup.
Install autossh
brew install autossh
Run a persistent local forward
autossh -M 0 -f -N \
-o "ServerAliveInterval=30" \
-o "ServerAliveCountMax=3" \
-L 3000:127.0.0.1:3000 \
-L 9223:127.0.0.1:9223 \
user@vps
Optional: SSH config snippet
Host vps-tunnel
HostName YOUR_VPS_IP
User root
LocalForward 3000 127.0.0.1:3000
LocalForward 9223 127.0.0.1:9223
ServerAliveInterval 30
ServerAliveCountMax 3
Then: autossh -M 0 -f -N vps-tunnel
After wake
If the Mac slept hard, check with lsof -iTCP:3000 -sTCP:LISTEN. No listener → restart autossh.