How to Configure Claude Code SSH Prevent Delete

Published
Length
4 min read

Luis Felipe Dias

All posts

To set up a claude code ssh prevent delete rule, restrict the remote Linux user. You should also keep the local agent in manual approval mode for shell commands. Many teams let coding agents use an engineer's personal SSH key to reach remote servers. That key often belongs to a remote user with full write and delete rights. If the agent misreads a prompt, it can remove critical files or folders right away. Giving an AI tool broad remote shell rights puts production systems at real risk. How a

Claude Code Security + SSH Access Management: the complete guide

Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.

Free white paper. No spam. Unsubscribe anytime.

To set up a claude code ssh prevent delete rule, restrict the remote Linux user. You should also keep the local agent in manual approval mode for shell commands. Many teams let coding agents use an engineer's personal SSH key to reach remote servers. That key often belongs to a remote user with full write and delete rights. If the agent misreads a prompt, it can remove critical files or folders right away. Giving an AI tool broad remote shell rights puts production systems at real risk.

How a native claude code ssh prevent delete setup works

Claude Code reaches external systems through the Model Context Protocol or its built-in Bash tool. When the agent uses its Bash tool, it runs shell commands on your local machine. In manual mode, the agent asks for your approval before it runs most commands. Only a small built-in list of read-only commands runs without a prompt. Still, an SSH command is just a single shell call to the local agent. Once you approve that SSH call, the remote server handles what happens next.

To stop file removal on the remote host, you must limit the remote Linux account. Start by creating a dedicated Linux user on the target host just for the agent. Do not put this user in any admin group or grant it root rights. Set file ownership and folder permissions so this user can only read files. When the operating system blocks write actions, the agent cannot delete files or folders. Even if the agent runs a delete command, the Linux kernel will reject it.

You can also use OpenSSH certificates to tighten how the agent logs in. OpenSSH lets a certificate authority key sign a user public key to create a certificate. This certificate holds a public key, identity details, allowed user names, and specific login options. Certificate login for users and hosts has been part of OpenSSH since version 5.4. Unlike standard keys that last forever unless removed, a certificate can include a validity window. You can also embed certificate options that restrict what the session can do after login. For example, a forced command option can run a single read-only script on login. That script can check the requested command and block any file delete calls.

What native controls solve and what they miss

Linux file permissions and OpenSSH certificates solve the basic problem of broad server login. A read-only Linux user stops the agent from wiping system folders or reading private keys. Short-lived certificates also mean a stolen key will not work forever on your hosts. Manual mode in the local agent gives engineers a chance to review shell commands first.

Claude Code Security + SSH Access Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Yet this native setup still leaves a major operational gap during real debugging work. Operating system permissions are static and apply to whole folders or files at once. Often, an engineer needs the agent to edit one config file or restart a service. If you grant write rights for that task, the user can also delete those files. SSH login rules decide who can log in, not what each command does in flight. Once an interactive shell opens, the server does not pause for approval on single commands. Relying on a human to read every long SSH command string also leads to mistakes. People get tired and click approve on complex shell strings without spotting a delete step.

Why wrapper scripts are hard to keep up

Some teams try to fix this gap by writing custom wrapper scripts on each host. The SSH key forces the session to run a custom bash or Python script first. That script reads the incoming command string and looks for words that remove files. While this sounds simple, shell syntax gives an agent many ways to remove data. An agent can overwrite a file with empty text or move it to a temp folder. It can also call a scripting language on the host to unlink a file directly. Maintaining a blocklist script across dozens of servers takes too much time for platform teams. Every time you update the script, you must push it to every single remote host. Also, standard SSH logs do not store the full text output of every remote session. If an agent changes a file or reads sensitive emails and phone numbers, logs miss it.

Inspect one-shot SSH commands and file tasks

SSH certificates and host rules decide who is allowed on a machine. Setup alone does not check single commands or block sftp reads on sensitive paths. By design, hoop.dev runs an inline open-source SSH listener on the host where engineers and AI agents keep their normal ssh, sftp, and scp tools. On every production command or file operation, hoop.dev decides whether to pass, mask, block, or hold it for approval.

First, hoop.dev guardrails check one-shot commands and file paths before they run, and hoop.dev data masking masks matched values in file downloads. The audit trail logs the certificate principal, requested action, and verdict without storing session content. Interactive shells carry no guardrails and can be turned off when every action must be checked. Explore the code on GitHub.

Frequently asked questions

Does Claude Code block remote SSH delete commands on its own?

No, the local agent only checks the initial shell command in manual mode. Once an SSH command runs, the remote host controls what files the session can delete.

How can a Linux host stop an SSH user from deleting files?

You can give the agent a dedicated Linux user with read-only folder and file permissions. You can also use an OpenSSH certificate or authorized key that forces a read-only script.

Why are read-only Linux users not always enough for coding agents?

Fixing often requires the agent to write logs, update configs, or restart an app service. Once you grant write rights to a folder, standard Linux permissions also allow file deletion.

Save the open-source gateway.

hoop is MIT-licensed infrastructure for controlling how AI agents reach production data. Star hoophq/hoop so you can inspect it, deploy it, or share it when your team starts governing agent access.