{"slug": "connect-claude-code-or-codex-to-a-raspberry-pi-without-sharing-your-password", "title": "Connect Claude Code or Codex to a Raspberry Pi Without Sharing Your Password", "summary": "A developer walkthrough shows how to give terminal-capable coding agents like Claude Code and Codex CLI SSH access to a Raspberry Pi using dedicated Ed25519 key pairs and ssh-agent, so the Pi's account password never passes through the model's prompt, scripts, or tool arguments. The setup is run manually outside the agent conversation, with host-key fingerprint verification and a note that key-based access still grants the remote account's full permissions rather than read-only access.", "body_md": "You want a coding agent to check a service on your Raspberry Pi. It needs to run a command over SSH, and the connection asks for a password.\n\nPasting that password into the conversation is an unnecessary step. Configure SSH authentication yourself, then let the agent invoke the SSH client. The client can authenticate without putting the Pi's password into a prompt, a script, or a tool argument.\n\nSSH keys are the right approach here. Raspberry Pi's own [remote access documentation](https://www.raspberrypi.com/documentation/computers/remote-access.html) describes key-based authentication for connections that don't require entering the account password each time.\n\nThere is a boundary worth understanding before setting this up: the agent will still be able to run commands with the remote account's permissions. Keeping a password out of the conversation does not make that access read-only.\n\nFor this walkthrough, assume Claude Code, Codex CLI, or another terminal-capable coding agent runs on your computer. That computer can already reach the Pi over your local network. The commands below use a Linux, macOS, or WSL shell with OpenSSH installed, and the Pi runs Raspberry Pi OS with SSH enabled.\n\nThe connection follows this path:\n\n*The SSH client handles authentication locally; the remote account determines what commands can do.*\n\nWith public-key authentication, SSH proves possession of the private key without sending that key to the server. A local `ssh-agent` can hold the unlocked identity and perform the authentication operations for the client. The language model does not need the private key contents or its passphrase. See the OpenSSH documentation for [SSH authentication](https://man.openbsd.org/ssh) and [ssh-agent](https://man.openbsd.org/ssh-agent).\n\nA cloud coding session is a different environment. It does not automatically inherit your laptop's SSH configuration, agent socket, or access to a private LAN. Start with a local CLI for this workflow.\n\nRun the setup commands yourself in a terminal outside the coding agent's conversation. Replace `labuser` and `192.168.1.50` throughout with your Pi's actual username and address. `labuser` is an example, not a default Raspberry Pi account.\n\nOn your computer:\n\n```\nssh-keygen -t ed25519 -f ~/.ssh/pi_lab_ed25519 -C \"pi-lab-access\"\n```\n\nChoose a passphrase when prompted. If the filename already exists, stop and choose another name rather than overwriting a key.\n\nThis produces two files:\n\n`~/.ssh/pi_lab_ed25519`: the private key, which stays on your computer.`~/.ssh/pi_lab_ed25519.pub`: the public key, which you install on the Pi.\nA dedicated key makes this connection easier to identify and revoke without changing unrelated SSH access.\n\nYou may have seen an example using `ssh-keygen -t ed25519 -b 4016`. Remove the bit-length argument: Ed25519 has a fixed key length, and OpenSSH [ignores `-b` for this key type](https://man.openbsd.org/ssh-keygen).\n\nCopy only the public key:\n\n```\nssh-copy-id -i ~/.ssh/pi_lab_ed25519.pub labuser@192.168.1.50\n```\n\nThis bootstrap step may ask for the Pi account password. Enter it directly into your own terminal. You are authenticating with SSH, without passing the password through the coding agent.\n\nOn the first connection, verify the Pi's host-key fingerprint before accepting it. From a trusted local console on the Pi, you can display its Ed25519 host-key fingerprint with:\n\n```\nssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub\n```\n\nCompare that fingerprint with the one presented by your client. If the client presents a different host-key algorithm, compare the corresponding host public key. Host-key checking helps establish that you reached the intended server; keep it enabled. OpenSSH explains this in its [host-key verification guidance](https://man.openbsd.org/ssh#VERIFYING_HOST_KEYS).\n\nIf `ssh-copy-id` is unavailable, use Raspberry Pi's [manual public-key installation instructions](https://www.raspberrypi.com/documentation/computers/remote-access.html). Preserve existing entries in `authorized_keys` when adding yours.\n\nCheck whether your shell already has access to an authentication agent:\n\n```\nssh-add -l\n```\n\nIf it reports that it cannot connect to an authentication agent, start one in this shell:\n\n```\neval \"$(ssh-agent -s)\"\n```\n\nThen load the key for one hour:\n\n```\nssh-add -t 1h ~/.ssh/pi_lab_ed25519\n```\n\nEnter the key passphrase in this terminal. OpenSSH's [`ssh-add` documentation](https://man.openbsd.org/ssh-add) covers both interactive passphrase entry and the identity lifetime option.\n\nThe distinction between the two passwords matters. The Pi account password protects account login. The key passphrase protects your private key on disk. You can keep that passphrase and still let subsequent SSH commands authenticate without prompting while the identity is loaded.\n\nLaunch your coding CLI from this shell so its subprocesses can inherit `SSH_AUTH_SOCK`, the environment variable that identifies the authentication agent's socket. An already-running application may have a different environment.\n\nAdd this host entry to `~/.ssh/config` on your computer, before broad `Host *` defaults:\n\n```\nHost pi-lab\n    HostName 192.168.1.50\n    User labuser\n    IdentityFile ~/.ssh/pi_lab_ed25519\n    IdentitiesOnly yes\n    PreferredAuthentications publickey\n    BatchMode yes\n    StrictHostKeyChecking yes\n    ForwardAgent no\n```\n\n`IdentitiesOnly` limits which identities SSH offers. `BatchMode` disables interactive authentication and confirmation prompts, so an unattended command fails instead of waiting for input. Strict host-key checking requires an already trusted host key. Agent forwarding is unnecessary for running commands on this Pi. These options are documented in the [OpenSSH client configuration reference](https://man.openbsd.org/ssh_config).\n\n*Example configuration for the `pi-lab` alias. Keep the copyable configuration above when adapting it to your machine.*\n\nBefore connecting, inspect the resolved settings with `ssh -G pi-lab`. This prints configuration without opening a remote session. The capture below uses `-F ./ssh-config` to inspect an isolated example file, so it does not depend on personal SSH settings.\n\n*Actual local OpenSSH output, typeset as a console capture. The hostname and username are examples; this is a configuration check, not a successful Pi login.*\n\nTest the alias yourself:\n\n```\nssh pi-lab 'hostname; whoami; uptime'\n```\n\nOnly proceed when this works without a password prompt. If authentication fails, check the public-key installation, username, loaded identity, and agent environment. A host-key failure needs verification, rather than a flag that bypasses the check.\n\nStart your preferred CLI from the prepared shell:\n\n```\nclaude\n# Or, for Codex CLI:\ncodex\n```\n\nThen give it a bounded first task:\n\n```\nThe Raspberry Pi is available through the SSH alias pi-lab.\nAuthentication is configured locally. Do not read or print private keys,\nrequest passwords, or change SSH configuration.\n\nRun this diagnostic command:\nssh pi-lab 'hostname; whoami; uptime; df -h /'\n\nReport the results. Ask before changing files, installing packages,\nrestarting services, or using sudo.\n```\n\nThe alias is enough connection information for the agent to invoke SSH. Its execution environment must still permit the network connection and access to the authentication socket. If a sandbox blocks either, review the specific restriction; successful SSH in your terminal does not establish that every agent subprocess has the same access.\n\nClaude Code documents its [permission controls](https://code.claude.com/docs/en/security) and [shell sandbox restrictions](https://code.claude.com/docs/en/sandboxing). Keep approvals scoped to the task rather than granting unrestricted shell access just to make a connection work.\n\nConsider the diagnostic command above. Its output includes a hostname, username, uptime, and disk usage. Later, you might ask for application logs, which could contain tokens or customer data. Treat output returned to the coding agent as material that may enter the model's context.\n\nAlso consider the account itself. A separate non-administrator account gives you a clearer starting point than your normal administrative login. Check its group memberships and sudo permissions: a new username does not establish limited access by itself.\n\nAn SSH key authorizes whatever that remote account is allowed to do. A prompt asking for read-only behavior is useful task guidance, but enforce stronger restrictions through remote permissions or, for narrow automation, a forced command in `authorized_keys`. OpenSSH documents [per-key restrictions and forced commands](https://man.openbsd.org/sshd#AUTHORIZED_KEYS_FILE_FORMAT).\n\nLikewise, `ssh-agent` is an authentication mechanism, not a barrier against every process running as your local user. A process with access to its socket can request authentication operations. If you need the private key to be inaccessible to the coding agent, enforce that with filesystem isolation, a separate user, or a hardware-backed key. Simply leaving the key outside the repository does not establish that boundary.\n\nThis is separate hardening, not a prerequisite for keeping the password out of the conversation.\n\nAfter key authentication works, keep an existing session open and retain a recovery route, such as a local console. On the Pi, configure these directives in the appropriate global SSH server configuration:\n\n```\nPubkeyAuthentication yes\nPasswordAuthentication no\nKbdInteractiveAuthentication no\n```\n\nKeyboard-interactive authentication is a separate mechanism that can also prompt for a password. Check included configuration files and `Match` sections, which can affect the settings that apply to your connection. See the [SSH server configuration reference](https://man.openbsd.org/sshd_config).\n\nValidate the configuration before applying it:\n\n```\nsudo /usr/sbin/sshd -t\n```\n\nYou can inspect effective settings with `sudo /usr/sbin/sshd -T`; connection-specific `Match` rules require the appropriate `-C` connection parameters. Both validation modes are described in the [`sshd` manual](https://man.openbsd.org/sshd).\n\nIf validation succeeds, reload the service on Raspberry Pi OS:\n\n```\nsudo systemctl reload ssh\n```\n\nOpen a second connection from your computer and confirm key authentication still works before closing the original session.\n\nFor a local Pi project, I would start with a dedicated key, a limited remote account, and one diagnostic command. That is enough to establish the workflow. Expand the account's permissions only when the next task requires them, and keep credential setup in your own terminal.", "url": "https://wpnews.pro/news/connect-claude-code-or-codex-to-a-raspberry-pi-without-sharing-your-password", "canonical_source": "https://dev.to/playfulprogramming/connect-claude-code-or-codex-to-a-raspberry-pi-without-sharing-your-password-29m4", "published_at": "2026-12-01 07:41:00+00:00", "updated_at": "2026-12-01 07:45:03.608608+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["Claude Code", "Codex CLI", "Raspberry Pi", "OpenSSH", "Anthropic", "OpenAI"], "also_reported_by": [], "takeaway": "Generate a dedicated Ed25519 key pair, install only the public key on the Pi with ssh-copy-id, and let ssh-agent handle authentication so the password never enters the agent's prompt or tool arguments.", "recommendation": {"advice": "Set up dedicated SSH keys and ssh-agent outside the agent's conversation so coding agents authenticate without passwords in prompts, and remember key access still carries the remote account's full permissions.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/connect-claude-code-or-codex-to-a-raspberry-pi-without-sharing-your-password", "markdown": "https://wpnews.pro/news/connect-claude-code-or-codex-to-a-raspberry-pi-without-sharing-your-password.md", "text": "https://wpnews.pro/news/connect-claude-code-or-codex-to-a-raspberry-pi-without-sharing-your-password.txt", "jsonld": "https://wpnews.pro/news/connect-claude-code-or-codex-to-a-raspberry-pi-without-sharing-your-password.jsonld"}}