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.
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:
| Setting | What it does | Use 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-authkeyCopied- Put every flag the server should have on this line.
--sshhere turns on Tailscale SSH. Adding one later withtailscale upis refused unless you repeat the rest, which is the “requires mentioning all non-default flags” error;tailscale setchanges one setting without it. --timeoutmatters in scripts. The default is0s, “which blocks forever”. A key that is not pre-approved on a tailnet with device approval printsTo approve your machine, visit (as admin):and a link, and waits there.- A tagged key needs no
--advertise-tags. The tags come from the key. You can name a different tag only if one of the key’s tags directly owns it intagOwners, and you cannot remove a key’s tags with the flag at all: generate a new key with the tags you want. - On AWS, as of 1.104.7 on 64-bit Linux,
--auth-keyalso accepts an AWS Parameter Store ARN (a value startingarn:aws:ssm:) and fetches the key from there, using the AWS SDK’s default credential lookup. - Under Tailnet Lock, generate the key pre-approved, sign it on a signing node with
tailscale lock sign <auth-key>, and join with the new key that command prints; otherwise each new machine is locked out until a signing node signs it.
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.
- Joined with an untagged key: node key expiry is on. Turn it off for a server: Machines, the menu at the end of its row, Disable Key Expiry.
- Joined with a tagged key: node key expiry is off from the start, because Tailscale disables it the first time a device authenticates with a tag.
- Tagged later in the admin console: the expiry stays as it was until the machine re-authenticates, so turn it off by hand.
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.txtCopiedfile:inTS_AUTHKEYis read as a path, per the image’s start-up code. Compose mounts each secret at/run/secrets/<name>, and Docker’s secrets page notes that environment variables “are often available to all processes”. Keepts_authkey.txtout of git and out of any image you build.TS_AUTH_ONCE=truelogs in only when the container is not already logged in. The default,false, “forces login every time the container starts”: the image runstailscale upwith the key on every start, which is the trap in the next section.TS_STATE_DIRon a volume keeps the machine’s identity; without it, Tailscale’s parameters page says, each restart creates a new node, which a one-off key cannot do twice. For a container that should vanish when it stops, leave the state out and use a reusable, ephemeral key instead.
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 existCopiedThe 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:serverCopied- Each run makes a fresh one-off key with those tags and uses it, so there is no key to renew.
- The defaults suit CI, not servers:
ephemeraldefaults totrueandpreauthorizedtofalse. Without?ephemeral=falsea server is removed, normally 30 to 60 minutes after it goes offline. - Tags are mandatory: without
--advertise-tagsthe CLI stops withoauth authkeys require --advertise-tags. The tags must be the client’s full set, or each one owned by one of the client’s tags intagOwners. A client with several tags that applies only some of them needs each of those tags listed as its own owner, per the tags page; otherwise the API answersrequested tags [tag:…] are invalid or not permitted.
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 .keyCopiedThe - 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:ciCopiedThe 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:serverCopiedElsewhere, 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:
backend error: invalid key: API key <key-id> not validA one-off key used a second time, the diagnosis a Tailscale contributor gave in #9715. Generate a new one-off key, or a reusable one if several machines need it.invalid key: API key does not existIn the reports, the “You are logged out” health line above, on a machine still started with an expired key. Take the key out of the start-up command; for a new join, generate a fresh key.backend error: invalid key: unable to validate API keyThe value is not a key at all, as reported for--authkey foobarin #6215 (Tailscale 1.44.0, 2023). Check for a truncated paste or changed case.oauth authkeys require --advertise-tagsandfederated identity authkeys require --advertise-tagsAn OAuth secret or a client ID was given with no tags.requested tags [tag:…] are invalid or not permittedThe tags asked for are not the OAuth client’s, or are a subset thattagOwnersdoes not allow (above).To approve your machine, visit (as admin):Not an error: device approval is on and the key was not pre-approved. Approve it on the Machines page, or use a pre-approved key next time.tailscale upwaits with no output Add--timeoutso a script fails instead of hanging, then readtailscale statusfor the health line.