How to Configure Gemini CLI SSH Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up gemini cli ssh least privilege by scoping host accounts and signing short-lived OpenSSH certificates. You also restrict which local shell commands the AI agent can run without asking. Many teams start by giving the agent their own daily SSH keys and admin accounts. That broad setup lets a single bad prompt alter production servers or expose sensitive files. How to set up gemini cli ssh least privilege with OpenSSH A coding agent runs inside your local terminal and inherits your she

Least Privilege Principle + 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.

You set up gemini cli ssh least privilege by scoping host accounts and signing short-lived OpenSSH certificates. You also restrict which local shell commands the AI agent can run without asking. Many teams start by giving the agent their own daily SSH keys and admin accounts. That broad setup lets a single bad prompt alter production servers or expose sensitive files.

How to set up gemini cli ssh least privilege with OpenSSH

A coding agent runs inside your local terminal and inherits your shell access. If your local user holds an open SSH key, the agent can use that key too. It can log in to remote hosts and run commands with your full remote rights. Limiting what the agent can do requires tightening both the local tool and the remote server.

First, create a dedicated Linux user on the remote host for agent tasks. Give this user read-only rights to log folders and app directories. Do not put this user in the admin group or grant root rights. Next, replace static public keys with OpenSSH user certificates signed by a certificate authority key. An OpenSSH certificate holds a public key, an identity string, principal names, and signed options. You can set a short time window when you sign the certificate. When the timer runs out, the certificate stops working on its own.

You can also embed command limits inside the signed certificate or the authorized keys file. This forces the remote server to run only one approved script when the user logs in. Even if the AI tool asks to run a different shell command, the server ignores it.

Why static host rules leave gaps in agent workflows

Host accounts and OpenSSH certificates control who logs in to a Linux machine. They work well when a person or script runs one fixed job every time. Still, an AI terminal agent needs to check logs, inspect processes, and read state across hosts. Locking a certificate to one fixed script breaks this kind of open debugging work.

If you allow general shell commands for debugging, the host cannot tell safe commands from risky ones. A read-only Linux user can still read private files that share group read permissions. The agent might pull customer emails, phone numbers, card numbers, or national IDs into its prompt context. Once that text enters the terminal output, the local agent sends it to the model provider.

Least Privilege Principle + SSH Access Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Local approval prompts inside the terminal tool also fall short for team safety. Developers get tired of clicking approve on dozens of routine shell checks during a busy day. They often turn on auto-run modes so the agent can move faster. Static SSH keys stored on laptops also stay at risk if an agent reads local disk files.

Scoping local agent permissions and shell environments

To lower risk on the client machine, run the CLI agent inside a separate local account. Do not give that local account read rights to your personal SSH folder or cloud keys. Keep your ssh-agent socket locked away from the shell session where the AI tool runs. This stops the agent from opening quiet background connections to hosts you did not approve.

You should also review the tool permissions list before starting a task. Only allow safe local file reads by default, and require manual checks for network calls. Keep project folders clean so the agent does not read old dumps containing emails or card numbers. Clear out temporary logs after each debugging session ends.

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

Can the CLI agent use my active SSH agent keys?

Yes, any process running in your user shell can talk to your local SSH agent socket. Run the AI tool in a separate user context or container to block key reuse.

How do OpenSSH certificates help with gemini cli ssh least privilege?

OpenSSH certificates let you sign a public key with a strict time limit and principal name. The access expires on schedule without leaving permanent keys on the remote server.

Why is a read-only Linux user not enough for AI agents?

A read-only user can still dump app configs or logs that hold emails and phone numbers. Host permissions cannot rewrite matched fields in results before they reach the model.

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.