HuggingRun / scripts /ssh_connect.sh
tao-shen's picture
feat: single-port SSH-over-WebSocket + full OS persistence
2a081e2
Raw
History Blame
1.74 kB
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────
# SSH into HuggingRun via WebSocket (single port 7860)
# No jumphost needed β€” SSH tunnels through the HF Space's web port.
#
# Prerequisites:
# brew install websocat # macOS
# # or download from https://github.com/nicehash/websocat/releases
#
# Usage:
# bash scripts/ssh_connect.sh # default: tao-shen-huggingrun.hf.space
# bash scripts/ssh_connect.sh my-space.hf.space # custom space URL
# SSH_USER=root bash scripts/ssh_connect.sh # login as root
# ─────────────────────────────────────────────────────────────────────
set -euo pipefail
SPACE_HOST="${1:-tao-shen-huggingrun.hf.space}"
SSH_USER="${SSH_USER:-user}"
WS_URL="wss://${SPACE_HOST}/ssh"
# Check websocat
if ! command -v websocat &>/dev/null; then
echo "websocat not found. Install it:"
echo " macOS: brew install websocat"
echo " Linux: curl -L -o ~/.local/bin/websocat https://github.com/nicehash/websocat/releases/latest/download/websocat.x86_64-unknown-linux-musl && chmod +x ~/.local/bin/websocat"
exit 1
fi
echo "Connecting to ${SSH_USER}@${SPACE_HOST} via WebSocket SSH ..."
echo " WebSocket: ${WS_URL}"
echo " Password: huggingrun"
echo ""
# SSH with WebSocket as ProxyCommand
ssh -o "ProxyCommand=websocat --binary ${WS_URL}" \
-o StrictHostKeyChecking=no \
-o UserKnownHostsFile=/dev/null \
"${SSH_USER}@huggingrun"