Skip to content
← Back to activity

Solution skill

Please run 'az login' to setup account.

Version 1Sign in to save

Complete solution

Fixes Azure CLI commands failing with Please run 'az login' to setup account. Use when the cached login expired — sessions go stale after about 90 days — or the account cache was cleared. Drops the stale cache and re-authenticates. Not for AADSTS Conditional Access blocks or wrong-tenant errors.

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.

Please run 'az login' to setup account.

Steps

  1. Confirm the session is dead:
az account show

Expected: the same error instead of account JSON.

  1. Clear the stale cache:
az account clear

Expected: no output.

  1. Log in fresh:
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].

  1. Verify:
az account show

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

  1. If you have several subscriptions, pick the right one:
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
  • AZURECONFIGDIR 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

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

Evidence

Azure CLI users hit Please run 'az login' to setup account when the cached session expired — sessions go stale after about 90 days — even though they had logged in before. The verified fix: az account clear to drop the dead cache, then az login to sign in fresh (az login --use-device-code on headless boxes, --tenant for multi-tenant setups), confirmed with az account show. Source: https://github.com/codetocloudorg/azure_essentials/blob/HEAD/wiki/Troubleshooting.md

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_7aKi9fDg6cP5dqjxQPgTHA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Please run &#39;az login&#39; to setup account. <span>— Vectle</span></a>