Codex CLI login fails on SSH or a headless box. Use device code or copy auth
codex login never finishes because the browser callback to localhost cannot reach the remote CLI, or token exchange fails behind a corporate proxy. Short answer: 5 steps. 1) Check what credential Codex thinks it has; 2) Prefer device code on remote or headless hosts; 3) Or copy a trusted auth.json from a machine that can log in; 4) Fix TLS inspection and dead proxies before you retry; 5) Use an API key when ChatGPT login is the wrong tool.
Last updated: · This page is the decision checklist; the tools list for “Fix Codex CLI login” is a separate URL.
How do I fix this: Codex CLI login fails on SSH or a headless box?
Check what credential Codex thinks it has
Run codex login status. If a stale session is half-present, run codex logout, then try a clean login. Direct login runs also write a codex-login.log under your Codex log directory for browser or device-code failures. Docs: https://developers.openai.com/codex/auth/
Prefer device code on remote or headless hosts
Browser login needs a localhost callback (default port 1455). On SSH, WSL without a browser, or when that callback is blocked, enable device code login in ChatGPT security settings (personal) or workspace permissions (admin), then run codex login --device-auth. Open the printed link on any browser, sign in, and enter the one-time code.
Or copy a trusted auth.json from a machine that can log in
On a machine with a working browser flow, run codex login, confirm ~/.codex/auth.json exists, then copy that file to the same path on the headless host (or into the container). Treat auth.json like a password: never commit it or paste it into chat. If your OS uses the keyring instead of a file, set cli_auth_credentials_store = "file" in config.toml first, or use the API-key path below.
Fix TLS inspection and dead proxies before you retry
If login fails with error sending request while curl to auth.openai.com works, check HTTP_PROXY/HTTPS_PROXY/ALL_PROXY and stale local proxy ports. For corporate TLS inspection, export CODEX_CA_CERTIFICATE=/path/to/corporate-root-ca.pem (or SSL_CERT_FILE) before codex login. Optionally forward the callback with ssh -L 1455:localhost:1455 and run the normal browser login in that session.
Use an API key when ChatGPT login is the wrong tool
For CI and other non-interactive local workflows, pipe a Platform key: printenv OPENAI_API_KEY | codex login --with-api-key. API usage bills at standard API rates and does not use ChatGPT plan credits. Enterprise automation that needs workspace entitlements can use printenv CODEX_ACCESS_TOKEN | codex login --with-access-token when an admin has granted access tokens.
Which tools are best to fix Codex CLI login?
Codex authentication
ChatGPT login, API key login, device code, custom CA, and headless fallbacks.
Codex CLI
Install and run the Codex command-line agent.
OpenAI API keys
Mint a key when you intend to bill Codex via API instead of ChatGPT.
CI/CD auth (advanced)
Trusted runners that refresh a copied auth.json between jobs.
Open: 1 spot per week
One labeled sponsor for this topic each week; this week's spot is open. See open weeks →
All tools for “Fix Codex CLI login” →
Related fixes
- Stop a Cursor agent loopHow to fix a Cursor agent loop (same edit, or work after Stop)Fix →
- Claude Code vs Codex vs Cursor ~$20 plansClaude Code vs Codex vs Cursor $20 plan limits: how to pick without burning the weekFix →
- Scan a vibe-coded app for leaked API keysCheck a vibe-coded app for leaked API keys before you share itFix →
- Add an MCP server to Claude Code, Cursor, or CodexHow to add an MCP server to Claude Code, Cursor, or CodexFix →
See also AI tools launched today on the daily board.
NewAIToolsToday Daily
Top 3 AI launches, one model or news item that matters, and one simple fix. A 5-minute read, every weekday.