Skip to content
Rotate › GitHub

How to rotate GitHub tokens: PATs, fine-grained tokens and App keys

GitHub has several kinds of credential, and they rotate differently. Personal access tokens are replaced by hand. GitHub App private keys can overlap. Installation tokens expire every hour on their own, which is why they're the one to move to.

Keysquid team · Updated · Checked against GitHub's docs on November 28, 2026

Token formats
ghp_ classic PAT, github_pat_ fine-grained PAT, gho_ OAuth, ghu_ user-to-server, ghs_ server-to-server (installation), ghr_ refresh token.
Where
Settings → Developer settings → Personal access tokens → Fine-grained tokens or Tokens (classic).
Revoke
Click Delete next to the token. Deleting a token that created a deploy key deletes that key too.
Expiry
Set at creation; defaults to 30 days. Organizations can enforce a maximum lifetime. Tokens unused for a year are removed.
Permissions
Fine-grained tokens: one owner, chosen repositories, read/write/admin per permission. Classic tokens: scopes, across every repo you can reach.
App private keys
Up to 25 per GitHub App, no expiry: generate a new one, deploy it, then delete the old one.
Installation tokens
Expire after 1 hour, and can be narrowed to specific repositories (up to 500) and permissions.
Keysquid
Automatic for GitHub App installation tokens. Personal access tokens are stored with rotation reminders.

Which GitHub credential do you have?

CredentialLifetimeHow it rotatesUse it for
Classic PAT (ghp_)Until it expires or is deletedCreate a new one, swap, delete the oldAvoid: it reaches every repo you can
Fine-grained PAT (github_pat_)You choose; default 30 daysCreate a new one, swap, delete the oldPersonal scripts against a few repos
GitHub App private key (PEM)No expiryGenerate a second key, deploy, delete the firstThe app's identity; signs JWTs
Installation token (ghs_)1 hourRequest a new one from the appServices, CI, bots

GitHub’s own advice: use fine-grained tokens instead of classic tokens whenever possible, and for access on behalf of an organization or for long-lived integrations, use a GitHub App. A rotation is a good time to make that move.

Rotate a personal access token

  1. Create the replacement under Settings → Developer settings → Personal access tokens. For a fine-grained token, pick the resource owner, only the repositories it needs, the minimum permissions, and an expiration.
  2. Swap it in wherever the old one is used. In GitHub Actions that’s usually a repository or organization secret:
    gh secret set DEPLOY_TOKEN --repo acme/api          # paste the new value when prompted
    gh secret set DEPLOY_TOKEN --org acme --visibility selected --repos api,web
  3. Run the workflow or script once with the new token.
  4. Delete the old token from the same settings page. There is no overlap setting to manage: the old token works until you delete it or it expires.

Leaked a token? Delete it first, then create the replacement. Check the repositories it could reach for pushes, new deploy keys, new webhooks and Actions runs you don’t recognise. GitHub’s guide to remediating a leaked secret covers cleaning up history.

Rotate a GitHub App private key

Because an app can hold up to 25 private keys at once, this rotation can be seamless:

  1. Open the app’s settings: Developer settings → GitHub Apps → Edit → Private keys, and click Generate a private key. GitHub downloads the PEM file and keeps only the public half.
  2. Deploy the new PEM to whatever signs the app’s JWTs.
  3. Confirm the app still authenticates (for example, by requesting an installation token).
  4. Delete the old key. An app must always keep at least one.

Better: stop rotating, use installation tokens

An installation token is requested from your GitHub App with a short-lived JWT signed by the app’s private key, and it expires after one hour. You can narrow each token to specific repositories and permissions when you request it:

curl -s -X POST "https://api.github.com/app/installations/$INSTALLATION_ID/access_tokens" \
  -H "Authorization: Bearer $APP_JWT" -H "Accept: application/vnd.github+json" \
  -d '{"repositories": ["api"], "permissions": {"contents": "read"}}'

The private key becomes the only long-lived secret, and it never needs to leave the service that mints tokens.

How Keysquid handles GitHub credentials

Automatic Keysquid creates, verifies, distributes and revokes GitHub App token keys on a schedule, with no one in the loop. Short-lived installation tokens instead of a long-lived personal access token.

Setup, as the app shows it:

  1. Create a GitHub App with only the permissions your service needs and install it on the repositories.
  2. Generate a private key for the app and paste it here.
  • Writes to: Installation token (default variable GITHUB_TOKEN), in every platform and secret store you map it to.
  • Interval: from every 30 minutes to every 50 minutes, subject to your plan’s minimum.
  • Note: Installation tokens expire after one hour, so this key rotates every 30–50 minutes.

Every rotation runs in the same order: create the new key, verify it, write it everywhere, redeploy where a platform needs it, and only then revoke the previous key after a grace period. If any write fails, everything written so far is restored and the new key is revoked. The value is encrypted to the agent you run, so Keysquid’s servers never see it.

Personal access tokens can’t be created through GitHub’s API, so Keysquid doesn’t rotate them. It recognises ghp_ and github_pat_ values when you import an environment, stores them like any other secret, keeps every platform in sync when you paste a new one, and reminds you on schedule. The better path is the one above: a GitHub App, which Keysquid rotates on its own.

Frequently asked questions

Can I rotate a GitHub personal access token automatically?

Not through GitHub's API: personal access tokens are created in your account settings. You can automate distributing the new token, but the cleaner fix is a GitHub App, whose installation tokens expire after an hour and are minted on demand.

What's the maximum lifetime of a fine-grained token?

You choose the expiration when creating it, and it defaults to 30 days. Organizations and enterprises can set a maximum lifetime policy that blocks longer ones, including non-expiring tokens.

How do I revoke a GitHub token?

Go to Settings → Developer settings → Personal access tokens, open Fine-grained tokens or Tokens (classic), and click Delete next to the token.

What do ghp_, github_pat_ and ghs_ mean?

ghp_ is a classic personal access token, github_pat_ a fine-grained personal access token, and ghs_ a server-to-server token such as a GitHub App installation token. gho_, ghu_ and ghr_ are OAuth, user-to-server and refresh tokens.

How many private keys can a GitHub App have?

Up to 25. That's what allows a zero-downtime rotation: generate a new key, deploy it, then delete the old one.

Sources

  1. GitHub docs: Managing your personal access tokens
  2. GitHub docs: Managing private keys for GitHub Apps
  3. GitHub docs: Generating an installation access token
  4. GitHub docs: Remediating a leaked secret
  5. OpenRouter: secret formats (GitHub token prefixes)
Rotate GitHub Tokens: PATs, Fine-Grained & App Keys