AI coding agents can now sign in to a server over SSH and run commands for you. Whatever account the agent uses, it can do everything that account can do, so the safe set-up is the one you would give a new contractor: its own user, its own SSH key, never root, only the access the job needs, a human approving anything that changes the server, and a backup taken first. Each of those steps also makes it easy to see what the tool did and to cut it off in one move.
An agent such as Anthropic's Claude Code or OpenAI's Codex works by running commands. On your own laptop, both tools can ask before each command and run inside a sandbox. Once the agent connects to a server over SSH, what it may do there is decided by the server: by the account it signs in as and the key it uses.
Two risks are specific to AI:
Neither risk is solved by a cleverer prompt. Both are solved by what the account is allowed to do.
OpenSSH, the SSH server on almost every Linux system, allows root to sign in with a key by default, and allows password sign-ins by default. Once your own key-based login works, set these in the SSH server's configuration and restart it:
PermitRootLogin no
PasswordAuthentication no
No person and no tool then signs in as root. Administrative work goes through sudo from a named account, where it is logged.
Our help article How to set up SSH key-based authentication on a Linux server covers the key set-up first.
Create a separate user for the agent, and a key pair used for nothing else:
ssh-keygen -t ed25519 -C "ai-agent laptop 2026-10"
The comment after -C is only a label for you, so you can tell keys apart later. One key per tool per machine means that removing the tool's access is deleting one line from the user's authorized_keys file, without touching anyone else's.
Where SSH keys are stored in Linux explains the files involved.
Each line in authorized_keys can carry its own restrictions, documented in OpenSSH's manual:
| Option | What it does |
|---|---|
from="203.0.113.10" |
The key works only from that address |
restrict |
Turns off port forwarding, agent forwarding and other extras |
command="..." |
The key can run only that one command |
expiry-time="20261231" |
The key stops working after that date |
For example:
restrict,from="203.0.113.10",expiry-time="20261231" ssh-ed25519 AAAA... ai-agent laptop 2026-10
An expiry date is a good habit for any key given to a tool: access lapses on its own if you forget.
If the agent needs administrative commands, give it only the specific ones. The sudo manual warns that granting ALL lets a user run anything, that "everything except" rules rarely hold, and that a program run with sudo can start other programs. Narrow is safe; clever exclusions are not. sudo logs every use, which gives you a record of what the agent did.
Use the agent's approval settings. Claude Code asks before edits and commands in its default mode, and Anthropic says its mode that skips approvals should be used only in isolated containers or virtual machines. Codex runs in a sandbox with network access off by default.
Read each proposed command before you approve it, especially anything that deletes, overwrites, restarts or changes permissions.
Anthropic notes that Claude Code's checkpoints undo file edits it made, not changes made by shell commands. On a server, a backup is the only undo.
journalctl.If you want a server set up for AI tools without handing any of them the keys to everything, ask Noiz for a Linux administration quote.
Note: while some of this content was produced with the help of AI, the final editing has been done by a real human being.