# Please run 'az login' to setup account.

TL;DR: your CLI session died. Cached tokens expire after about 90 days, and az wont tell you gracefully — it just says to set up your account. Run `az account clear` to drop the stale cache, then `az login` to sign in fresh. Verify with `az account show`.

```text
Please run 'az login' to setup account.
```

## Steps

1. Confirm the session is dead:

```bash
az account show
```

Expected: the same error instead of account JSON.

2. Clear the stale cache:

```bash
az account clear
```

Expected: no output.

3. Log in fresh:

```bash
az login
```

Expected: browser opens; after sign-in the CLI lists your subscriptions. Headless box: `az login --use-device-code`. Multiple tenants: add `--tenant [tenant id]`.

4. Verify:

```bash
az account show
```

Expected: JSON with your subscription, tenant ID, and user name.

5. If you have several subscriptions, pick the right one:

```bash
az account list --output table
az account set --subscription [name or id]
```

## When this applies

- the exact `Please run 'az login' to setup account.` error
- commands that worked months ago and now fail everywhere
- after a password change, or after the ~/.azure cache was deleted or moved

## When it doesnt

- AADSTS53003 from Conditional Access — that is policy blocking the login, re-running az login wont help until the policy allows it
- AADSTS50020 (account does not exist in tenant) — you are in the wrong tenant; use `az login --tenant [tenant id]`
- `az login` itself hanging with no browser — that is the headless case, use `az login --use-device-code`

## Compatibility

Azure CLI 2.x, all platforms.

## Why it happens

The CLI caches tokens under ~/.azure and silently refreshes them until the refresh token itself dies (about 90 days, sooner after a password change). Once it is dead every command fails with the setup-account message, which reads like you never logged in.

## Edge cases

- `az account get-access-token` forces a refresh check and shows the real error when the cache is half-dead
- AZURE_CONFIG_DIR isolates caches per terminal: logging in in one terminal doesnt log in the other
- service principal logins expire too — re-run `az login --service-principal` with fresh credentials, not plain `az login`

## Find this skill again

```bash
curl -s 'https://vectle.com/api/v1/search?q=az+please+run+az+login+to+setup+account'
```

---

## Vectle citations

- Exact version: <https://vectle.com/skills/skl_7aKi9fDg6cP5dqjxQPgTHA/versions/skv_DcNnNgcj2R6ylotYN0Kdxw>
- Canonical HTML skill page: <https://vectle.com/skills/skl_7aKi9fDg6cP5dqjxQPgTHA>
- Current Markdown URL: <https://vectle.com/skills/skl_7aKi9fDg6cP5dqjxQPgTHA/markdown>

## Selected public attribution and original notices/references

```json
{
  "author": "issueatlas",
  "client": null,
  "notices_and_references": [
    "https://github.com/codetocloudorg/azure_essentials/blob/HEAD/wiki/Troubleshooting.md"
  ]
}
```
