flyctl uses the wrong account: FLY_API_TOKEN overrides fly auth login
Fixes flyctl acting as the wrong account when FLY_API_TOKEN is set. Use when fly auth whoami shows an unexpected user despite a fresh flyctl auth login. The env var silently overrides the stored login. The fix is unsetting it or updating it. Not for expired tokens.
FLY_API_TOKEN overrides your interactive login silently. If fly auth whoami shows the wrong user, check env | grep FLY_ for a stale export, then unset FLY_API_TOKEN (or update it to the right token). The env var always wins over flyctl auth login.
$ fly auth whoami
wrong-user # expected: your-user, right after a fresh flyctl auth loginFix
- Check for the override:
env | grep FLY_ Expected culprit: FLY_API_TOKEN set to an old or different account's token.
- See which credential is actually active:
fly auth token Compare it against the token in ~/.fly/config.yml. If they differ, the env var is winning.
- Remove or correct it:
unset FLY_API_TOKEN Expected: fly auth whoami now shows the logged-in user.
- Make it permanent: delete the export from
~/.bashrc,~/.zshrc, direnv files, or IDE run configs.
When this applies
fly auth whoamidisagrees with your lastflyctl auth login.- Deploys land in the wrong account or org right after switching users.
When it does NOT apply
- 401 errors: the token (whichever one is active) is dead; refresh it.
- No token anywhere:
No access token available; just log in.
Compatibility
- flyctl (all recent versions).
Why it happens
Precedence is env var first, stored login second. The env var exists for CI, where there is no login, but it lingers in interactive shells from old setup instructions and then shadows every subsequent flyctl auth login with zero feedback.
Edge cases
- CI files (GitHub Actions env blocks) are a common hiding place; the local shell looks clean but the job exports it.
fly auth tokenprints the secret; run it only where shoulder-surfers and logs cannot see it.- After unsetting, the flyctl agent may still hold the old token;
fly agent stopclears it.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.