Fix Codex sign-in that never completes on a remote or headless machine

Codex's browser sign-in returns your credentials to a local callback server on localhost:1455. On SSH sessions, servers, and containers, that callback can't be reached, so sign-in hangs. Use codex login --device-auth instead. Or forward the port with ssh -L 1455:localhost:1455, or copy ~/.codex/auth.json from a machine where you signed in.

Applies to: Codex CLI, SSH, Docker, Linux servers

Option 1: Device code (preferred)

  1. Enable device code login in your ChatGPT security settings. If you’re in a workspace, ask your admin to enable it.

  2. On the remote machine:

    codex login --device-auth
  3. Open the link on any device, sign in, and enter the one-time code.

Option 2: Forward the callback port over SSH

From your local machine:

ssh -L 1455:localhost:1455 user@remote

In that SSH session, run codex login and open the printed address in your local browser.

Option 3: Copy the auth cache

Sign in on a machine with a browser, then copy the cache:

ssh user@remote 'mkdir -p ~/.codex'
scp ~/.codex/auth.json user@remote:~/.codex/auth.json

For Docker:

CONTAINER_HOME=$(docker exec MY_CONTAINER printenv HOME)
docker exec MY_CONTAINER mkdir -p "$CONTAINER_HOME/.codex"
docker cp ~/.codex/auth.json MY_CONTAINER:"$CONTAINER_HOME/.codex/auth.json"

This only works if your local Codex stores credentials in a file. If it uses the OS keyring, set cli_auth_credentials_store = "file" first. Treat auth.json like a password.

For automation

For CI and scripts, OpenAI recommends an API key: printenv OPENAI_API_KEY | codex login --with-api-key.

Questions people ask

Device code sign-in isn't offered. Why?

It's in beta and must be enabled first, in your ChatGPT security settings for a personal account or in workspace permissions by an admin.

Where can I find logs for a failed login?

Direct codex login runs write a codex-login.log file under your configured log directory.

Sources

We link to the official source for every instruction on this page. If anything here disagrees with them, trust the official source and tell us.