GuidesSecurity

Tailscale auth key: options, Docker, expiry and OAuth

Generate a Tailscale auth key, use it with tailscale up or TS_AUTHKEY, what a tag does to key expiry, OAuth and identity federation, and the invalid key errors.

November 23, 2026The Everpod team
The short answer

A Tailscale auth key (it starts tskey-auth-) adds a machine to your tailnet without a browser sign-in. On the admin console’s Keys page, select Generate auth key, choose one-off or Reusable, an expiry of 1 to 90 days (90 if you leave it), and the device settings Ephemeral, Pre-approved and Tags. Then run sudo tailscale up --auth-key=file:/path/to/key on the server, or set TS_AUTHKEY in the tailscale/tailscale container. The key’s expiry only limits when it can add machines: the machine’s own node key expires after 180 days by default, unless the key carried a tag, which turns that expiry off. Give the key on the first start only. For keys nobody renews by hand, pass an OAuth client secret (tskey-client-…, with the auth_keys scope) where the key would go, or use workload identity federation, which stores no secret at all on GitHub Actions, AWS and Google Cloud.

Generating a key, and what each setting does

An Owner, Admin, IT admin or Network admin of the tailnet opens the Keys page of the admin console, selects Generate auth key, fills in the form and selects Generate key. Copy it then: Tailscale’s Docker guide warns that after you close the dialog “you cannot view it again”, and keys are case-sensitive. As of November 2026, the form’s settings, from Tailscale’s auth keys page:

SettingWhat it doesUse it for
Reusable
Off (the default): one machine, then Tailscale revokes the key. On: any number of machines until it expires.On only for a fleet that joins on its own. A stolen reusable key adds machines to your tailnet; Tailscale says it is “best kept in a key vault”.
Expiration
1 to 90 days; left empty, 90. After it, the key cannot add machines. Machines it already added stay.The shortest window the job needs. There is no longer-lived key; see OAuth clients below.
Ephemeral
The machine is removed, normally 30 to 60 minutes after its last activity, or at once on tailscale logout, and gets a new IP next time.CI jobs and throwaway containers. Never a server you will SSH into tomorrow.
Pre-approved
Skips device approval. Offered only when the tailnet has device approval turned on.Servers on a tailnet with approval on; without it, tailscale up waits for an admin.
Tags
The machine takes the tag’s identity instead of yours, and its node key expiry starts off. Each tag must already exist in the policy file’s tagOwners.Servers, containers and runners: anything that is not a person’s own device.

Without a tag, the key “authenticates a device as the user who generated the key”: the server joins as you, is matched by your access rules, and, by default, can reach and be reached like your laptop. For a server that runs an AI agent that is the wrong default, and locking down an agent server with a tag and Tailscale SSH has the policy to put in place before a tagged key is used. Ephemeral machines also count against a monthly allowance of ephemeral minutes that varies by plan; one that stays four hours or more counts as an ordinary tagged device instead.

Joining a server with tailscale up

--auth-key takes the key itself or, if the value begins with file:, a path to a file holding it. The file form keeps the key out of your shell history, which Tailscale’s guide to handling auth keys warns about, and out of the running command’s line in /proc/<pid>/cmdline. The CLI trims whitespace from what it reads, so a trailing newline does no harm:

umask 077
cat > ~/ts-authkey          # paste the key, press Enter, then Ctrl+D
sudo tailscale up --auth-key=file:$HOME/ts-authkey --ssh --timeout=2m
rm ~/ts-authkey
Copied

If the server is a container with no /dev/net/tun, tailscaled stops before the key is ever used; Tailscale in a container covers that error. Once the machine is in, a one-off key is spent and Tailscale revokes it. Revoking a reusable key on the Keys page (you can revoke only keys you made) stops further joins but, in Tailscale’s words, “does not deauthorize nodes using the key”: remove those from the Machines page.

The machine’s own key expiry, and what a tag changes

Two expiries are in play, and they do different things. The auth key’s expiry ends its ability to add machines; per Tailscale, “any device authorized by it remains authorized until its node key expires.” The node key is the machine’s own, made when it logs in, and on Tailscale’s key expiry page it expires after 180 days on a new tailnet (any period from 1 to 180 days can be set under Device management, Key Expiry). When it does, connections to and from that machine stop.

If a server’s node key has already expired, Temporarily extend key in the same menu gives you 30 minutes to get in and disable expiry.

In a container: TS_AUTHKEY

The tailscale/tailscale image logs in with whatever is in TS_AUTHKEY. Tailscale’s own Compose example pastes the key into the file; this version reads it from a Compose secret instead and logs in only once:

services:
  tailscale:
    image: tailscale/tailscale:latest
    environment:
      - TS_AUTHKEY=file:/run/secrets/ts_authkey
      - TS_AUTH_ONCE=true
      - TS_STATE_DIR=/var/lib/tailscale
      - TS_HOSTNAME=agent-box
    volumes:
      - ./tailscale-state:/var/lib/tailscale
    secrets:
      - ts_authkey
    restart: unless-stopped

secrets:
  ts_authkey:
    file: ./ts_authkey.txt
Copied

An OAuth client secret works in TS_AUTHKEY too, with TS_EXTRA_ARGS=--advertise-tags=tag:<name> beside it; the container is then ephemeral unless you append ?ephemeral=false to the secret. The newer form is TS_CLIENT_ID with TS_CLIENT_SECRET (which also takes file:). Mixing the two forms is refused at start with TS_AUTHKEY cannot be used with TS_CLIENT_ID, TS_CLIENT_SECRET, TS_ID_TOKEN, or TS_AUDIENCE. The container itself uses Docker’s DNS rather than MagicDNS unless TS_ACCEPT_DNS=true is set; other containers on a Tailscale host losing DNS is a different problem, in Docker containers losing DNS or internet with Tailscale.

Give the key once, not on every start

As of 1.104.7, tailscale up hands the key to tailscaled whenever --auth-key is on the command line, whether or not the machine is already logged in (the CLI source skips its edit-only path whenever a key is given). Tailscale’s tracker has an open issue, #16987, with reports from Linux and OPNsense of machines that joined fine, still had the key in their start-up command, and came back from a restart logged out. The tailscaled log in the duplicate report, #19501 (Tailscale 1.96.5), shows:

health(warnable=login-state): error: You are logged out. The last login error was: invalid key: API key does not exist
Copied

The opening report ties it to the key having expired, and says it shows up only several days after that, not on the day, so a machine can run for months before a restart shows it. In #19501, removing --auth-key from the start-up command brought the machine back without a new login. No Tailscale maintainer had answered either issue by November 23, 2026, so the advice that follows is the reporters’ workaround: put the key only in the step that runs once, when the machine is set up, never in a systemd unit, an entrypoint or a boot script that runs every time. A bare tailscale up sends no key and, on a machine still logged in, only brings the connection up, changing no settings. In the container, that is what TS_AUTH_ONCE=true does: later starts run tailscale set instead of logging in again.

OAuth clients: keys nobody has to rotate

Tailscale is direct about the limit: “You cannot generate long-lived auth keys, because they expire after 90 days, or, for one-off keys, as soon as you use them.” The answer for automation is an OAuth client that makes keys on demand. In the admin console, open Trust credentials, select Credential, then OAuth, give it write access to auth keys (the auth_keys scope), pick the tags its machines will carry, and select Generate credential; the secret, which starts tskey-client-, is shown once. Pass it where a key would go, quoted so the shell leaves the ? and & alone:

sudo tailscale up \
  --auth-key='tskey-client-XXXX?ephemeral=false&preauthorized=true' \
  --advertise-tags=tag:server
Copied

The trade-off is that the secret never expires. Tailscale’s trust credentials page says it “can be used to generate access tokens indefinitely until it is revoked,” and revoking it does not revoke the auth keys it already made. On a machine that runs an agent, that is a standing credential for adding machines to your tailnet. The tighter pattern keeps the secret where you provision from, mints a one-off key that lasts an hour, and hands the new machine only that:

TOKEN=$(curl -s -d "client_id=$TS_API_CLIENT_ID" -d "client_secret=$TS_API_CLIENT_SECRET" \
  https://api.tailscale.com/api/v2/oauth/token | jq -r .access_token)

curl -s -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
  https://api.tailscale.com/api/v2/tailnet/-/keys \
  -d '{"capabilities":{"devices":{"create":{"reusable":false,"ephemeral":false,"preauthorized":true,"tags":["tag:server"]}}},"expirySeconds":3600}' \
  | jq -r .key
Copied

The - stands for the client’s own tailnet, and the last line prints the new tskey-auth- key. Tailscale’s get-authkey tool does the same from the same two environment variables, if Go 1.23 or later is installed: go run tailscale.com/cmd/get-authkey@latest -tags tag:server (one-off, not ephemeral and pre-authorized unless told otherwise).

Workload identity federation: no secret stored at all

Workload identity federation lets a CI job or cloud VM prove who it is with the token its platform already issues, which Tailscale swaps for a short-lived access token and then a key. Set it up under Trust credentials, Credential, OpenID Connect: pick the issuer, give the subject to match (* matches any characters), add the auth_keys scope and tags, and copy the Client ID and Audience, which are not secrets. In GitHub Actions, with the official action (v4.4.0, October 2026):

permissions:
  id-token: write

steps:
  - name: Tailscale
    uses: tailscale/github-action@v4
    with:
      oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
      audience: ${{ secrets.TS_AUDIENCE }}
      tags: tag:ci
Copied

The action marks its machines ephemeral and pre-approved, and they log out when the run ends. With an OAuth client instead, replace audience with oauth-secret. On a tailnet with Tailnet Lock, the action’s README says to use a pre-signed, ephemeral, reusable auth key rather than an OAuth client.

Outside the action, Tailscale 1.94.0 and later fetch the platform’s token themselves on AWS (a service such as EC2, ECS or EKS, with an IAM role attached and outbound identity federation enabled), Google Cloud (such as Compute Engine or GKE, with a service account) and GitHub Actions:

sudo tailscale up --client-id='<client-id>?ephemeral=false&preauthorized=true' \
  --audience=<audience> --advertise-tags=tag:server
Copied

Elsewhere, pass the provider’s signed token with --id-token=file:<path> (1.90.1 and later); in the container, the same pair is TS_CLIENT_ID with TS_AUDIENCE or TS_ID_TOKEN. Write both options out, as above: the docs say ephemeral defaults to true, but in the 1.104.7 code that default holds only when the client ID carries no options, so ?preauthorized=true alone registers a machine that is not ephemeral. A rejected exchange explains nothing in its reply (“Unauthorized. Visit [link to admin console] for details”); the reason is on the credential’s page under Trust credentials. For internal tools that should create machines owned by a person rather than a tag, Tailscale has a separate route, device provisioning with OAuth apps.

The errors, and what each one means

From tailscale up, a refusal from Tailscale’s servers is printed after backend error:, and its wording says “API key” even for an auth key. The forms reported in Tailscale’s tracker, and the CLI’s own:

Run Claude Code, Codex, OpenCode, Pi, Hermes or OpenClaw on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.