How to Configure Gemini CLI SSH Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up gemini cli ssh prevent delete rules, restrict the remote Linux user and command list. You also need to require human approval before the agent runs shell tools. Many teams give AI agents a normal developer SSH key to check remote servers. When that account has broad write rights, one bad command can wipe critical files. How gemini cli ssh prevent delete works in native setups Gemini CLI runs local shell commands on your machine to finish coding and ops tasks. When it needs to check

SSH Access Management + End-to-End Encryption: 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 gemini cli ssh prevent delete rules, restrict the remote Linux user and command list. You also need to require human approval before the agent runs shell tools. Many teams give AI agents a normal developer SSH key to check remote servers. When that account has broad write rights, one bad command can wipe critical files.

How gemini cli ssh prevent delete works in native setups

Gemini CLI runs local shell commands on your machine to finish coding and ops tasks. When it needs to check a remote host, it calls your local OpenSSH client. The agent uses whatever SSH keys and config files sit in your home folder. By default, the remote host treats the agent just like the human key owner.

To stop file deletion natively, you must change how the target Linux host handles logins. First, create a dedicated Linux user on the remote host just for the agent. Do not put this user in any admin group or grant root privileges. Next, set file ownership so this user only has read rights on app folders.

You can also use OpenSSH certificates or authorized key options to limit remote actions. OpenSSH lets you bind a specific public key or certificate to a single forced command. When the agent logs in with that key, the server runs a wrapper script instead. This wrapper script checks the command text and blocks requests that remove files or folders.

Why native SSH restrictions leave gaps for AI agents

Native Linux permissions and wrapper scripts work well for fixed, single-purpose tasks. They verify who can log in and which basic script starts the session. Still, AI agents need to run varied commands to debug live servers. Writing a bash wrapper script to parse every possible shell flag is very hard.

Attackers or confused models can bypass simple text filters in a shell script. For example, an agent might delete data using Python, Perl, or a file overwrite. Standard Linux permissions also apply to whole folders rather than individual command intent. If an agent needs write rights to fix a config file, it can also delete it.

SSH Access Management + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Local SSH keys create another risk on the developer laptop. If the agent can read the local key file, it can open new sessions freely. Native OpenSSH logs show who logged in, but they do not capture every shell command. Teams also cannot mask sensitive data like emails or card numbers in terminal output. You need a way to inspect and approve individual commands in flight.

Steps to harden remote agent sessions

Start by separating human SSH keys from the keys your AI tools use. Issue OpenSSH user certificates signed by a central key authority with short life spans. An OpenSSH certificate holds a public key, identity data, allowed principals, and signed options. Short certificate windows stop an agent from running tasks after a work shift ends.

Next, keep human confirmation turned on inside your local agent settings. Check every remote command string before you let the tool send it over SSH. Do not allow autonomous execution modes when the agent reaches production or staging hosts. Combine read-only Linux groups with strict command inspection to keep remote files safe.

Add command and file guardrails to SSH access

Host firewalls and certificate principals control who opens an SSH session. Yet an allowed user or agent can still run a bad one-shot command or pull sensitive files over sftp. In practice, hoop.dev sits inline on the host as an open-source SSH server with guardrails that uses OpenSSH certificates. For every one-shot command or sftp task an agent or human runs in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev SSH controls, guardrails check one-shot commands, env variable names, and sftp or scp paths before they run. Port forwards default to deny unless the target is listed. Because interactive shells have no statement boundary and carry no guardrails, teams can turn them off so every command is checked and logged. Check out the MIT-licensed project on GitHub.

Frequently asked questions

Can OpenSSH block delete commands by itself?

OpenSSH does not inspect or block specific shell commands like file deletes on its own. It can only force a login to run a custom script that you write and maintain.

Why can an AI agent delete files even without root rights?

If the remote Linux user owns a folder or shares a write group, it can delete files there. Standard file permissions do not separate creating files from removing them on most systems.

How do OpenSSH certificates help secure Gemini CLI sessions?

OpenSSH certificates let you set a strict validity window and force specific session options. The key stops working once the time window ends, which limits unattended agent runs.

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.