Codex login link doesn't work from ssh server

Resolved 💬 10 comments Opened Aug 25, 2025 by benWindsorCode Closed Sep 3, 2025
💡 Likely answer: A maintainer (bolinfest, collaborator) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.23.0

Which model were you using?

N/A (couldn't get past login)

What platform is your computer?

Linux 6.8.0-71-generic x86_64 x86_64

(its an ubuntu server)

What steps can reproduce the bug?

To reproduce bug:

  1. connect to ssh server (so no browser available on the box)
  2. install codex 'sudo npm install -g @openai/codex'
  3. run 'codex' to trigger setup -> choose to 'Sign in with ChatGPT'
  4. paste the required link into the browser (browser won't open automatically as this is via ssh the box itself doesn't have a browser)
  5. You will get the following error:

'Oops, an error occurred!
Route Error (400 Invalid Session): "Your authorization session was not initialized or has expired"'

<img width="633" height="487" alt="Image" src="https://github.com/user-attachments/assets/bcd4f579-796f-47df-a1ac-786a54c63210" />

What is the expected behavior?

I should be able to paste the link into my browser and complete the login.

What do you see instead?

You will get the following error:
'Oops, an error occurred!
Route Error (400 Invalid Session): "Your authorization session was not initialized or has expired"'

<img width="633" height="487" alt="Image" src="https://github.com/user-attachments/assets/030503dd-6076-4eac-bbd5-4b083c882250" />

Additional information

Note: I am a user who logs into chat gpt via the 'login with google' integration, not sure if this is impacting

I have tried from a local session (rather than over ssh) and the link when opened in browser automatically (as my local machine of course has a browser installed) worked fine.

View original on GitHub ↗

10 Comments

digitalmagnets · 10 months ago

FWIW this morning, I have managed to do to the ssh login with a remote linux box and normally use login with google. Didn't work first time as it probably timed out but on second attempt it worked. This is using 0.23.

SauersML · 10 months ago

Log in to with your local machine. Copy the contents of ~/.codex/auth.json and place the contents in ~/.codex/auth.json in the ssh'd session (where you want to use codex).

Then, run codex normally and it should work. ($CODEX_HOME was not set for me.)

bolinfest collaborator · 10 months ago
Log in to with your local machine. Copy the contents of ~/.codex/auth.json and place the contents in ~/.codex/auth.json in the ssh'd session (where you want to use codex). Then, run codex normally and it should work. ($CODEX_HOME was not set for me.)

$CODEX_HOME is assumed to be ~/.codex if not set.

I see now that's not mentioned in those docs, only https://github.com/openai/codex/blob/main/codex-rs/config.md.

tibo-openai collaborator · 10 months ago

See information above shared by @bolinfest and we'll continue to improve our auth methods and documentation, thank you!

DMwarrior · 9 months ago

我已经实现了VScode远程链接服务器端的codex,首先需要再服务器端安装Clash verge,打开全局,然后在终端设置nano ~/.bashrc
export http_proxy=http://127.0.0.1:7897
export https_proxy=http://127.0.0.1:7897
export all_proxy=socks5://127.0.0.1:7897
source ~/.bashrc
就可以了,然后就可以在window打开vscode使用ssh连接远程服务器的codex,

westie-will · 8 months ago
Please see https://github.com/openai/codex/tree/main?tab=readme-ov-file#connecting-on-a-headless-machine

does not work been trying for hours to connect my codex cli to my remote ssh vps its so easy with claude code... the tunnel dont even work in cmd in windows. trash.

strongpapazola · 8 months ago

✅ Workaround: log in to Codex running on a remote server via SSH port forwarding

The login flow usually opens a local URL (e.g. http://localhost:1455/...). If Codex is running on a remote server, clicking that link on your laptop won’t reach the server’s localhost. Fix: forward the server’s port to your machine, then copy-paste the URL into your local browser.

Steps
  1. Start Codex on your server so it prints a “login in browser” URL (often http://auth.openai...?...).
  2. On your local machine, open a new terminal and create a local forward:

_Linux/macOS:_

ssh -N -L 1455:localhost:1455 root@YOUR_SERVER

_Windows (PowerShell with OpenSSH):_

ssh -N -L 1455:localhost:1455 root@YOUR_SERVER

_PuTTY:_ Connection → SSH → Tunnels → Source port: 1455 | Destination: localhost:1455AddOpen.

  1. Copy the full URL printed by Codex on the server (e.g. http://auth.openai...?...).

Do not click it remotely. Paste it into your local browser’s address bar. Thanks to the tunnel, your local http://localhost:1455 now points to the server’s localhost:1455.

  1. Complete the login in your local browser. Codex on the server should confirm the authentication.
Why this works

-L 1455:localhost:1455 maps your localhost:1455server localhost:1455. The login URL assumes the service is on the same localhost as the browser. The tunnel makes that true from your machine.

Tips / Troubleshooting
  • Verify the service is listening on the server:

ss -ltnp | grep 1455
# or:
netstat -tulnp | grep 1455

  • Use a different local port if needed (open http://localhost:9000/...):

ssh -N -L 9000:localhost:1455 root@YOUR_SERVER

  • Keep the SSH window open, or auto-reconnect with autossh:

autossh -M 0 -N -L 1455:localhost:1455 root@YOUR_SERVER

  • If SSH is not on 22, specify the port:

ssh -p 2222 -N -L 1455:localhost:1455 root@YOUR_SERVER

  • If the link opens in the wrong app, copy the URL as text and paste it manually into your browser.
chunjie-sam-liu · 7 months ago

@SauersML solution works me. This is a common issue for now remote ssh user. Hope it can implement the auth like geminni-cli or like github authentication.

etraut-openai contributor · 7 months ago

@chunjie-sam-liu, we have a new feature available (in preview) that is intended to address this use case. For details, refer to this post.