How does Codex connect to a server over SSH?

Codex, in the ChatGPT desktop app, finds hosts in your ~/.ssh/config, resolves them with OpenSSH and starts its remote app server over SSH. Its documentation shows a key and never mentions a password, so move a host that asks for one to a key first.

Last updated

Commands checked on Ubuntu 24.04.5 LTS (the ubuntu:24.04@sha256:562111b88caa79c71391c0c4d3c2114a7d5c35915c20561fd893cb1e07929e6b container image), .

Give the host a Host alias in ~/.ssh/config, with HostName, User and an IdentityFile. Check that ssh alias works from the machine that runs the ChatGPT desktop app, then add the host in the app under Settings > Connections. The Codex documentation shows a key in its example and does not mention passwords, so a host that only takes a password should get a key before you connect Codex to it.

What this article says about Codex comes from the Codex page on remote connections, read on 2026-11-29. The ssh commands ran against two server containers. I did not run Codex.

What the Codex page says

For an SSH host the page gives four steps. Add the host to your SSH config. Confirm that you can SSH to it from the machine running the app. Install and authenticate Codex on the remote host. Then open Settings > Connections in the app, add or enable the host and choose a remote project folder.

Codex reads concrete host aliases from ~/.ssh/config, resolves them with OpenSSH and ignores pattern-only hosts, so a block that says only Host * is not a host to it. The app starts the remote Codex app server through SSH, using the remote user’s login shell, and remote chats run commands and write changes on the remote host.

The example on the page has an alias, a HostName, a User and an IdentityFile. Here is the same block before the key line is added. The key is in ~/.ssh/codex_key, a name that ssh does not try on its own:

$ cat ~/.ssh/config
Host devbox
    HostName devbox.example.test
    User deploy

Test it the way an app would

You are told to run ssh devbox first. Add BatchMode=yes, which turns off every question, and you see what a connection does when nobody can answer:

$ ssh -o BatchMode=yes devbox hostname; echo "exit status: $?"
deploy@devbox.example.test: Permission denied (publickey).
exit status: 255

The server wants a key and ssh had none to offer. The -v option shows what it tried, and the line to look for is Offering:

$ ssh -v -o BatchMode=yes devbox hostname 2>&1 | grep -E 'Offering|Authentications that can continue|Permission denied'
debug1: Authentications that can continue: publickey
deploy@devbox.example.test: Permission denied (publickey).

No Offering line means ssh offered no key at all. The key sits in a file with a name ssh does not know to try. Tell it, and add IdentitiesOnly so that keys from an ssh-agent do not crowd in; the manual says it makes ssh use only the identity files named in the configuration or on the command line, even if the agent offers more:

$ printf '    IdentityFile ~/.ssh/codex_key\n    IdentitiesOnly yes\n' >> ~/.ssh/config
$ ssh -v -o BatchMode=yes devbox hostname 2>&1 | grep -E 'Offering|Server accepts|Permission denied|^devbox'
debug1: Offering public key: /home/dev/.ssh/codex_key ED25519 SHA256:BY+9j8cSHC7cmo3k7lPht/4XtWFYJgN/gy/C1A0NaFw explicit
debug1: Server accepts key: /home/dev/.ssh/codex_key ED25519 SHA256:BY+9j8cSHC7cmo3k7lPht/4XtWFYJgN/gy/C1A0NaFw explicit
devbox

The path in the Offering line is the answer to which key was used, and explicit says the config named it. The last line is the output of hostname on the server. How ~/.ssh/config is read, and in which order, is in the config file article.

A host that asks for a password

The second server takes passwords and has no key of yours. Here is what ssh says to it when it cannot ask:

$ ssh -v -o BatchMode=yes deploy@oldbox.example.test hostname 2>&1 | grep -E 'Authentications that can continue|No more authentication|Permission denied'
debug1: Authentications that can continue: publickey,password
debug1: No more authentication methods to try.
deploy@oldbox.example.test: Permission denied (publickey,password).

The server offers a key and a password. ssh has no key that fits, and it may not ask for the password, so it stops. The Codex page does not say how the app starts ssh or whether it can show a password prompt. BatchMode stands in for a connection with nobody at a keyboard, and such a connection ends with this refusal.

Put your key on the host. ssh-copy-id has to ask for the password once. In this check a small script answers for me through SSH_ASKPASS_REQUIRE=force; you type it yourself:

$ SSH_ASKPASS=$HOME/askpass SSH_ASKPASS_REQUIRE=force ssh-copy-id -i ~/.ssh/codex_key.pub deploy@oldbox.example.test
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/dev/.ssh/codex_key.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'deploy@oldbox.example.test'"
and check to make sure that only the key(s) you wanted were added.
$ ssh -o BatchMode=yes -i ~/.ssh/codex_key -o IdentitiesOnly=yes deploy@oldbox.example.test hostname
oldbox

The second command is the check: the login works with no question asked. The SSH keys article covers making the key, and the article on AI agents on servers says why the account on that host should be one made for the agent.

The command must be found in the login shell

The page says codex must be on the PATH of the remote user’s login shell. Here a program called codex sits in ~/.local/bin, which this account’s ~/.profile adds to the PATH at login. It is a stand-in script, not Codex:

$ ssh -o BatchMode=yes devbox 'command -v codex'; echo "exit status: $?"
exit status: 1
$ ssh -o BatchMode=yes devbox 'bash -lc "command -v codex"'
/home/deploy/.local/bin/codex

A plain remote command does not find it, and a login shell does. Test with the second form, for the login shell of the account.

Mistakes people make

You put the key settings only in a Host * block and nothing under the alias. Codex ignores pattern-only hosts, so the alias must exist as a concrete Host line. The settings of a Host * block still apply to it when OpenSSH resolves the alias.

You test with your agent loaded and a different key answers. Run the check with -o IdentitiesOnly=yes -i and the key you mean, as above.

You open the app server to a network. The page says not to expose app-server transports directly on a shared or public network. The app-server page says the same for the Codex CLI terminal UI: plain WebSockets only for localhost or an SSH port-forwarded connection. It marks the WebSocket transport experimental and unsupported.

You connect with your own account and key. Remote chats run commands and write changes on that host, so use an account made for the agent, with no more rights than the work needs.

In Valakes

Codex can also reach your servers through Valakes; the Codex page has the setup. Valakes makes the SSH connection, so the host does not need a Codex entry in ~/.ssh/config. For a saved password the agent writes the placeholder {{cred:name}} and Valakes answers the prompt, so Codex never sees the value. A host stays closed to agents until you open it, and an agent can never accept a host key.

Codex can reach your servers through Valakes, which holds the SSH connection and answers a password prompt from its vault, so Codex never sees the password. Feature: AI agents

References

The app is free.

Get notified at launch

macOS is coming to the Mac App Store. iOS and Android later.