# How does Codex connect to a server over SSH?

Codex in the ChatGPT desktop app reads host aliases from ~/.ssh/config and connects over SSH. Which key it uses, and why a password host fails.

Source: https://valakes.com/learn/codex-ssh/

Last updated: 2026-11-29

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.

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

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:

```console
$ 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:

```console
$ 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`:

```console
$ 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:

```console
$ 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](https://valakes.com/learn/ssh-config-file/).

## 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:

```console
$ 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:

```console
$ 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](https://valakes.com/learn/ssh-keys/) covers making the key, and [the article on AI agents on servers](https://valakes.com/learn/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:

```console
$ 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](https://valakes.com/agents/codex/) 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.

## In Valakes

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](https://valakes.com/features/ai-agents/)

[Read the docs: Agents](https://docs.valakes.com/agents/)

## References

- [Codex documentation, remote connections](https://learn.chatgpt.com/docs/remote-connections)
- [Codex documentation, app server](https://learn.chatgpt.com/docs/app-server)
- [ssh(1) on Ubuntu 24.04, the option -v and the variable SSH_ASKPASS_REQUIRE](https://manpages.ubuntu.com/manpages/noble/man1/ssh.1.html)
- [ssh_config(5) on Ubuntu 24.04, IdentityFile, IdentitiesOnly and BatchMode](https://manpages.ubuntu.com/manpages/noble/man5/ssh_config.5.html)
- [ssh-copy-id(1) on Ubuntu 24.04](https://manpages.ubuntu.com/manpages/noble/man1/ssh-copy-id.1.html)

## Related articles

- [How do I give an AI agent SSH access with the least damage?](https://valakes.com/learn/ai-agents-on-servers/): Give the agent its own account on the server, with no sudo, no password in the prompt and nothing secret in its reach. Let it read first, allow root for one exact command at most, make every change wait for a person, and keep a record of what ran.
- [How do I generate an SSH key and put it on a server?](https://valakes.com/learn/ssh-keys/): Run ssh-keygen -t ed25519, then ssh-copy-id -i ~/.ssh/id_ed25519.pub user@host. The private key stays on your computer, the public key goes into ~/.ssh/authorized_keys on the server, and you log in without a password.
- [SSH config file (~/.ssh/config): examples that work](https://valakes.com/learn/ssh-config-file/): The file ~/.ssh/config stores the address, user, port and key of each server under a short name. After that, ssh app does the work of a long command.
- [Can Claude Code SSH into a server?](https://valakes.com/learn/claude-code-ssh/): Yes. Claude Code has a shell, so it can run ssh host 'command' from your machine. It can also run on the server itself, and the desktop app sets that up with its SSH sessions. What the agent can reach, and where your key ends up, depends on the setup you choose.
