Skip to content

How to give Claude Code or Cursor SSH access to a server, safely

Give the agent its own unprivileged SSH user with a narrow sudoers file, save that user as a host in ShellVibe with a max access level, and connect the agent to ShellVibe's local MCP server. The agent then works through ShellVibe: it never sees the key, risky commands wait for your approval, and everything it runs is logged.

Why not just give the agent your ssh key

An agent with your key in its shell has everything you have: every server in your ~/.ssh/config, root wherever you have it, and no record beyond its own scrollback. Nothing asks you before rm -rf runs, and taking the access back means rotating the key. Through ShellVibe the key stays in your vault, the agent sees hosts as opaque ids, you set a ceiling per host, and one button revokes the lot.

1. Create a least-privilege user on the server

On the server, create a user for the agent. Do not add it to sudo or wheel.

sudo useradd --create-home --shell /bin/bash agent
sudo install -d -m 700 -o agent -g agent /home/agent/.ssh

On your own machine, make a key for it:

ssh-keygen -t ed25519 -f ~/.ssh/shellvibe_agent -C "shellvibe agent"

Put the public half on the server, with forwarding switched off:

echo 'no-port-forwarding,no-agent-forwarding,no-X11-forwarding ssh-ed25519 AAAA... shellvibe agent' \
  | sudo tee /home/agent/.ssh/authorized_keys
sudo chown agent:agent /home/agent/.ssh/authorized_keys
sudo chmod 600 /home/agent/.ssh/authorized_keys

To let it read system logs without root, add it to the journal group:

sudo usermod -aG systemd-journal agent

2. Write a narrow sudoers file

Grant only the commands the job needs, as full paths with fixed arguments. NOPASSWD matters: an agent session has no terminal to type a password into.

sudo visudo -f /etc/sudoers.d/agent
agent ALL=(root) NOPASSWD: /usr/bin/systemctl restart nginx, /usr/bin/systemctl reload nginx

Check what it ended up with:

sudo -l -U agent

Avoid entries that hand out a shell: editors, bash, less, find, or anything with a wildcard argument. ShellVibe classifies a command that starts with sudo as privilege, so it is refused on Read only and asks on the other two levels. The sudoers file is what still holds if a command gets past that check.

3. Add the host in ShellVibe

  1. Add the private key ~/.ssh/shellvibe_agent to the vault as an identity. Then delete the private key file (keep the .pub) and do not load it into ssh-agent: an agent with a local shell could otherwise read it straight off your disk.
  2. Create a host with the server's address, user agent, and that identity. Try connection tests the login before you save.
  3. In the host's AI access section, leave Allow AI agents on and choose Max access:
    • Read only runs only commands recognised as read-only.
    • Ask before changes asks you first. New hosts start here.
    • Full access runs changes without asking. Deletes, sudo, secret reads and unreadable scripts still ask, and anything the classifier does not recognise runs.
  4. Connect once from a terminal tab and accept the host key. An agent cannot accept an unknown key: it gets HOST_KEY_UNTRUSTED until you have.

4. Turn on AI access and connect the agent

In Settings → AI access, switch on Allow AI agent access. It is per workspace, and the agent only ever sees hosts in that workspace.

Under Connect an AI tool, click Claude Code, Claude Desktop, Cursor, Codex or Antigravity, then restart that tool. For any other MCP client, paste the JSON block shown below the list into its MCP config.

For Claude Code, Codex and Cursor on macOS and Linux you can also switch on Send ssh, scp, sftp and rsync to ShellVibe. It turns the agent's own ssh calls back towards ShellVibe's tools. It is a nudge, not a lock.

5. What the agent sees

Ask the agent to check disk space on the server. It calls list_hosts and gets something like:

{
  "workspace": { "id": "…", "name": "Production" },
  "hosts": [
    { "id": "3f0c…", "label": "web-1", "maxMode": "guarded",
      "groups": ["web"], "access": "none", "mode": null }
  ]
}

No address, no user name, no key. To do anything it calls request_host_access with the host ids and a reason, then open_session and run_command.

6. How approvals look

The first window is the access request: the agent's name, its reason, each host with its own level, and one duration for the grants (Once, 15 minutes, This session or Always). Approve some, deny others, or Deny and suspend client.

After that, df -h simply runs. A command like sudo systemctl restart nginx opens a second window with the command, the host and a label such as "Privilege escalation", and waits. You can remember the answer for that exact command on that host. Leave any window for two minutes and it counts as a no.

While it works, each agent session shows as a read-only terminal tab, so you see every command and its output as it happens.

7. Review the audit log, and the kill switch

The AI activity panel in Settings → AI access lists live grants and remembered approvals, each with its own revoke, and opens the audit log. The log records host requests, sessions, commands, transfers and runbook runs with the agent, host, risk category and decision. Filter it by client, host, decision or category, and export it as JSON or CSV.

If anything looks wrong, press Cut all agent access. It closes every agent session, revokes every grant, remembered approval and client token, and stops the server, without asking twice.

What this does not do

The command check reads shell text with patterns: a guide, not a sandbox. Output redaction masks known secret patterns, not every secret. What holds is your approval, the user and sudoers file from steps 1 and 2, and the audit log with its kill switch. More on each control in AI access, and on the rest of the app in Security model.