When Logging into the VPS via Codex CLI, the browser callback is usually stuck not due to incorrect account or password, but because the remote server cannot receive the login result from the local browser. First, run device code login to complete authorization on a computer or phone with a browser; the VPS terminal only waits for the result.
First, confirm your current login status
Running in VPS:
if codex login status; then echo "Codex 已有有效登录"
else echo "需要重新登录"
fiIf the status shows login, do not grant multiple authorizations; At this point, continue checking the workspace or package permissions. If the status is invalid, execute codex logout to clear old credentials to avoid overdue sessions interfering with new logins.
If there is no graphical interface, use the device code
codex login --device-authThe terminal will provide an authorization address and a one-time code. Open this address on your own computer or phone, log in to the correct ChatGPT account, enter the code, then return to the VPS and wait for completion. The device code option needs to be enabled first in the personal account security settings; For team accounts, the administrator may need to grant the corresponding permissions.
What to do if you can't see the device code options?
First, confirm that Codex CLI is updated, then check whether your account or workspace allows device code login. If still unavailable, you can create a local SSH port forwarding to allow the standard browser's local callback back to VPS; By default, the callback uses localhost:1455.
Automate tasks without relying on browser login
Unattended tasks like CI and scheduled scripts are more suitable for API Keys. Put the key into the server environment variable or key manager, then log in using standard input:
printenv OPENAI_API_KEY | codex login --with-api-keyAPI Key charges based on API usage and is not equivalent to ChatGPT workspace permissions. Do not paste keys or ~/.codex/auth.json into chats, logs, or code repositories; Finally, use codex login status to confirm which login method is currently used.