Skip to content

Instantly share code, notes, and snippets.

@supersonictw
Last active May 30, 2024 07:39
Show Gist options
  • Save supersonictw/6f98d8c5f2d1850b91fbddb8ebf1ef23 to your computer and use it in GitHub Desktop.
Save supersonictw/6f98d8c5f2d1850b91fbddb8ebf1ef23 to your computer and use it in GitHub Desktop.
#!/bin/bash
# SSH + WebSocket
# License: MIT (https://ncurl.xyz/s/RD0Yl5fSg)
# https://gist.github.com/supersonictw/6f98d8c5f2d1850b91fbddb8ebf1ef23
# Client:
# ssh -o ProxyCommand="wstunnel client -L stdio://%h:%p ws://example.com:2530" 127.0.0.1
WSTUNNEL_DOWNLOAD="https://github.com/erebe/wstunnel/releases/download/v9.6.1/wstunnel_9.6.1_linux_amd64.tar.gz"
WSTUNNEL_TMP_PATH_PREFIX="/tmp/wstunnel"
WSTUNNEL_INSTALL_PREFIX="/usr/local/bin"
mkdir -p "$WSTUNNEL_TMP_PATH_PREFIX" "$WSTUNNEL_INSTALL_PREFIX"
wget -O "$WSTUNNEL_TMP_PATH_PREFIX/wstunnel.tar.gz" $WSTUNNEL_DOWNLOAD
tar -zxf "$WSTUNNEL_TMP_PATH_PREFIX/wstunnel.tar.gz" -C "$WSTUNNEL_TMP_PATH_PREFIX"
SUDO=''
if [ "$EUID" != 0 ]; then
SUDO='sudo'
fi
$SUDO apt-get install -y openssh-server
$SUDO install "$WSTUNNEL_TMP_PATH_PREFIX/wstunnel" "$WSTUNNEL_INSTALL_PREFIX/wstunnel"
$SUDO tee "/lib/systemd/system/sshws.service" <<EOF
[Install]
WantedBy=multi-user.target
[Unit]
Description=Transfer SSH protocol with WebSocket
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
Restart=always
User=nobody
ExecStart=$WSTUNNEL_INSTALL_PREFIX/wstunnel server --restrict-to 127.0.0.1:22 http://127.0.0.1:2530
EOF
$SUDO systemctl daemon-reload
$SUDO systemctl enable --now "sshws.service"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment