Skip to content

Instantly share code, notes, and snippets.

@dadevel
Created August 10, 2025 14:47
Show Gist options
  • Save dadevel/3c3793fd401c64db03e6f3e512f1a198 to your computer and use it in GitHub Desktop.
Save dadevel/3c3793fd401c64db03e6f3e512f1a198 to your computer and use it in GitHub Desktop.
Tailscale Authkey Generator
#!/usr/bin/bash
set -euo pipefail
shopt -s lastpipe
curl -sSf 'https://api.tailscale.com/api/v2/oauth/token' -d "client_id=${TS_CLIENT_ID:?client id missing}" -d "client_secret=${TS_CLIENT_SECRET:?client secret missing}" | jq -r .access_token | read -r token
jq -n --arg reusable "${TS_REUSEABLE:-false}" --arg ephemeral "${TS_EPHEMERAL:-false}" --arg tag "${TS_TAG:?tag missing}" --arg expiry "${TS_EXPIRY:-3600}" --arg description "${TS_DESCRIPTION:-}" '{"capabilities":{"devices":{"create":{"reusable":$reusable|toboolean,"ephemeral":$ephemeral|toboolean,"preauthorized":true,"tags":["tag:\($tag)"]}}},"expirySeconds":$expiry|tonumber,"description":$description}' | curl -sSf 'https://api.tailscale.com/api/v2/tailnet/-/keys?all=true' --oauth2-bearer "${token}" --json @- | jq -r .key | read -r authkey
echo "${authkey}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment