Skip to content

Instantly share code, notes, and snippets.

@spacelatte
Last active June 5, 2019 12:04
Show Gist options
  • Save spacelatte/a8d03847506f31d4b569a5bcb9d830ee to your computer and use it in GitHub Desktop.
Save spacelatte/a8d03847506f31d4b569a5bcb9d830ee to your computer and use it in GitHub Desktop.
#!/bin/bash
PORT=${PORT:-22}
SOCK=${SOCK:-/tmp/$(hostname).sock}
ps aux \
| grep -v grep \
| grep ssh \
| grep "$@" \
| grep -qi "$SOCK:0:$PORT" \
|| ssh -vNC \
-oCompression=yes \
-oGatewayPorts=yes \
-oTCPKeepAlive=yes \
-oConnectTimeout=9 \
-oConnectionAttempts=3 \
-oServerAliveCountMax=9 \
-oServerAliveInterval=5 \
-oUserKnownHostsFile=/dev/null \
-oExitOnForwardFailure=yes \
-oStrictHostKeyChecking=no \
-oStreamLocalBindUnlink=yes \
-R $SOCK:0:$PORT $@ \
&
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment