Skip to content

Instantly share code, notes, and snippets.

@jasalt
Created January 3, 2024 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasalt/33e0048d0222669e866efc15f1574007 to your computer and use it in GitHub Desktop.
Save jasalt/33e0048d0222669e866efc15f1574007 to your computer and use it in GitHub Desktop.
SSH straight to server behind dynamic NGROK address/port using new NGROK API
#!/usr/bin/env bash
# Connect to a dynamic NGROK endpoint that changes ofter after server restart etc.
# Works with single active tunnel (per account) on free tier.
# Provides persistent or dedicated endpoint like premium experience.
# Requires environment variable $NGROK_APIKEY
NGROK_ENDPOINT=$(curl -s https://api.ngrok.com/tunnels -H "authorization: Bearer $NGROK_APIKEY" -H "ngrok-version: 2" | jq -r '.tunnels[0].public_url')
NGROK_HOST=$(echo "$NGROK_ENDPOINT" | cut -d':' -f2 | cut -d'/' -f3)
NGROK_PORT=$(echo "$NGROK_ENDPOINT" | cut -d':' -f3)
ssh -p $NGROK_PORT as@$NGROK_HOST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment