Security habits from day one to advanced setups
Keep this checklist handy to protect your keys, keep everything updated, set limits for agents, and know what to do when something goes wrong. It covers both the basics and advanced practices.
In this guide
Guide checked 3 months ago: some commands may have changed. Let us know if so.
In short
A mini-PC that stays on, is reachable from anywhere, and runs AI-written code needs a few good security habits. The ten-point checklist starts with two-factor authentication, SSH keys, no direct Internet exposure, secrets outside Git and chat, API spending caps, automatic updates, reboots after kernel updates, an agent without sudo, and tested backups. Keys tend to leak through Git history, logs, screenshots, and agent transcripts on disk. Block agents from reading your .env files and scan every commit. Update the OS, kernel, firmware, agents, Docker images, and dependencies, and give newly published packages time before installing them. For advanced setups, use one account per service, harden systemd units, and run a Lynis audit. If a key leaks, revoke it first and investigate afterward.
Do this first: Securing accessReview, audit, secure
Your mini-PC is an attractive target for three reasons. It runs day and night, you can reach it from anywhere, and it executes code written by an AI that never second-guesses itself. A few good habits go a long way. Start with the basics in your first week, then move on to advanced practices if you host services or work for other people.
For step-by-step instructions, see Securing access for SSH, firewalls, and secrets, Review, audit, secure for agent-written code, and Maintain and update for upkeep. This checklist brings those topics together and fills in the gaps.
The basics: ten boxes to tick
Check them off as you go. The site remembers your progress.
0 of 10 steps done Your ticks stay in this browser.
-
Turn on two-factor authentication everywhere
GitHub, Anthropic, OpenAI, Google, Cloudflare, Tailscale, and your domain registrar. These accounts can give someone control of your machine. Use a passkey or an authenticator app and avoid SMS if you have a choice.
-
Keep services off the public Internet
Your router should forward no ports to the mini-PC. Use Tailscale to reach it and a Cloudflare tunnel for anything that needs to be public. Check what is actually listening:
sudo ss -tlnp # each line is a service waiting for connectionsAnything listening on
0.0.0.0or[::]is reachable from your local network. Ollama, databases, and admin interfaces should listen on127.0.0.1. -
Keep secrets out of Git and chat
Set your
.envfile tochmod 600, list it in.gitignore, and keep keys out of conversations with your agent. See Securing access for details. -
Set a spending cap on each API key
The Anthropic, OpenAI, and OpenRouter consoles, among others, let you cap monthly spending. If a key is stolen, the cap limits the damage to your bank account.
-
Reboot when the kernel changes
Automatic updates install the new kernel, but the old one runs until you reboot. Kernel flaws are among the most serious. Numerama reported on CIFSwitch, a Linux vulnerability that had been around since 2007 (in French). This file appears when a reboot is pending:
cat /var/run/reboot-required 2>/dev/null || echo "Pas de redémarrage en attente" -
Run the agent as your user, with no automatic sudo
Start it inside the project directory and keep its work there. See Set limits for the agent.
-
Keep your agents updated
Claude Code updates itself. OpenCode, Codex, Ollama, and the others need a weekly update or a scheduled task. See Maintain and update.
-
Keep an off-machine backup and test a restore
Until you’ve restored something, you’re trusting a guess. Try recovering at least one file from your NAS or backup service. When you need it for real, check the backup before rebuilding anything by hand.
Keep keys from leaking
Most keys leak in ordinary ways.
Where keys actually leak
- Git history. A key you commit and delete in the next commit stays in the history, including on GitHub. Bots harvesting public repositories can find it within minutes.
- Agent transcripts. Claude Code keeps conversations in
~/.claude/projects/(30 days by default, configurable withcleanupPeriodDays). Codex keeps them in~/.codex/sessions/. If the agent reads a.envfile, the key can end up there in plain text and travel with any unencrypted home-directory backup. - Logs. A script prints its configuration at startup, or an error echoes the
Authorizationheader, and the key ends up injournalctl. - Screenshots and screen sharing. Think of a terminal recorded for a demo or a screenshot sent over Slack.
- Code sent to the browser. An API key in a web page’s JavaScript is public however you hide it. Route paid API calls through your server.
- Shared configuration files. A committed
.mcp.jsonoropencode.jsoncan expose a key if it contains the value directly. Reference a variable instead.
How to protect your keys
Block Claude Code from reading secret files in ~/.claude/settings.json (all projects) or .claude/settings.json (one repository):
{
"permissions": {
"deny": [
"Read(./.env)",
"Read(./.env.*)",
"Read(./secrets/**)"
]
}
}
A deny rule takes effect immediately, even in a repository you haven’t approved yet. Check with /permissions.
In opencode.json, the permission key sets each tool to allow, ask, or deny. Use deny for secret files and ask for reads outside the project. See the OpenCode documentation for the exact syntax.
With --sandbox workspace-write, Codex asks before working outside the project folder, but it can read what’s inside, including .env. Keep secrets outside the repository (in ~/.config/mon-projet/, for example) and pass them through environment variables, or through env_key for model providers.
Check each commit before it goes out. Gitleaks detects keys for most services:
gitleaks git . # scans the full repository history
gitleaks dir . # scans the files currently on disk
To run Gitleaks before every commit, use the hook it supplies for pre-commit. Its project page has the configuration. GitHub’s push protection rejects a git push that contains a recognized key. It’s enabled by default for public repositories. For eligible private repositories, turn it on in settings.
Keep everything up to date
There’s more to updating than running apt upgrade. Here are six layers, from the most automated to the easiest to overlook.
| Layer | How | How often |
|---|---|---|
| Operating system | unattended-upgrades for security, sudo apt update && sudo apt full-upgrade for the rest | Automatically, plus a manual update once a month |
| Kernel | Reboot when /var/run/reboot-required exists | After each new kernel |
| Firmware | sudo fwupdmgr refresh && sudo fwupdmgr update (BIOS, SSDs, and network cards that support it) | Every three months |
| Agents and tools | claude update, opencode upgrade, reinstall Ollama and Codex with their scripts | Weekly |
| Docker images | docker compose pull && docker compose up -d in each project | Monthly or whenever there’s an alert |
| Project dependencies | Dependabot or Renovate on GitHub, npm audit, pip-audit | On every alert |
Dependencies are a growing target. A worm hit keyv, an npm package used by millions of projects (in French), and Clubic described malicious npm packages that used ordinary PNG images (in French). Build three habits:
- Install from the lockfile. Use
npm ciin place ofnpm install, oruv syncin place of an ad hocpip install, to get the exact versions you’ve already checked. - Give new releases time. Malicious packages are usually spotted and removed within a few days. pnpm can reject releases younger than a set age (
minimumReleaseAge). uv can ignore releases newer than a given date (--exclude-newer). - Check each dependency the agent adds. AI models sometimes invent plausible library names, and attackers publish packages under those names. Clubic reported that nearly 800 npm packages exploit these hallucinations (in French). Before accepting a dependency, check its exact name, publisher, and download count.
Agents are eager colleagues
An agent wants to get the job done and can get creative. Numerama reported on a user whose agent, asked to book a fitness class, ended up hacking the gym (in French), and on OpenAI agents that hacked Hugging Face to pass an internal test (in French). The agents ran into obstacles and tried to get around them. Set these ground rules:
- Grant the fewest permissions possible. Start with read-only access, enable writes when needed, and require approval for anything that costs money or publishes content.
- Enable the sandbox. Use
/sandboxin Claude Code and--sandbox workspace-writein Codex. Reserve permission bypass mode for disposable containers. - Watch what the agent reads. A web page, ticket, or email can contain hidden instructions. Keep access to outside content and the ability to send data out in separate agent sessions. MCP servers come with risks of their own.
- Review its output, including security fixes. See Review, audit, secure.
Advanced practices
If the mini-PC hosts services for other people or runs client code, add another layer.
-
One Linux user per service. Run each service under its own system account, with no shell or access to your home directory. A compromised service can only see what belongs to it.
-
Harden your systemd services. A few lines in the
[Service]section close off a lot of access:NoNewPrivileges=yes,ProtectSystem=strict,ProtectHome=yes, andPrivateTmp=yes. UseReadWritePaths=for the paths the service actually needs to write to. Then check the score:systemd-analyze security mon-service.service # from 0 (locked down) to 10 (wide open) -
Run containers without root. Use rootless Docker or Podman to limit what a container escape can do to the host. See Docker: isolate your projects.
-
Encrypt secrets at rest. Use
sopswithageto store secrets in a repository without exposing them, or systemd’s encrypted credentials (LoadCredentialEncrypted=) for services. See Securing access for the full list of options. -
Set access rules in Tailscale. By default, all your devices can see each other. Access rules (ACLs) limit which device can reach which service. Your phone probably doesn’t need to reach the database.
-
Audit regularly. Lynis reviews the machine and ranks its recommendations. Run
sudo lynis audit systemagain after each major change. -
Set up alerts. Get notified when a systemd unit fails, the disk fills up, or an SSH connection comes from an unusual device. See Know when things break. Trigger a test alert to make sure it reaches you.
When something goes wrong
A key leaks, a service behaves strangely, or the agent runs a command it shouldn’t have. The order matters.
0 of 5 steps done Your ticks stay in this browser.
-
Cut off access first
Revoke the key with the provider before doing anything else, even before working out what happened. If the machine itself is involved, disconnect it from the network (or stop Tailscale and the tunnel). Leave the power on so you can inspect memory and logs.
-
Replace the keys
Create new keys, update them in your
.envfiles and services, and restart anything that uses them. -
Assess the damage
Check the provider console for unusual calls or spending, read the logs (
journalctl --since "2 days ago"), and check Git history, running processes, and scheduled tasks (systemctl list-timers,crontab -l). -
Clean up or restore from backup
Use
git filter-repoto remove a key from Git history and treat it as permanently public. If you doubt the integrity of the machine, rebuild it from a clean backup. That’s faster than tracking down every change. -
Write down what happened
Put three lines in the project’s
CLAUDE.mdorAGENTS.mdcovering what happened, why, and which rule will prevent it from happening again. The agent will read them every session, and so will you.
All the commands in this guide
Frequently asked questions
What should I do if I pushed an API key to GitHub?
Revoke it with the provider immediately, before cleaning up the repository. Bots scan GitHub constantly and can use an exposed key within minutes. Create a new key, check the provider console for unauthorized use, then clean up the history. Deleting the file in a new commit leaves the key in Git history.
Do coding agents store my secrets anywhere?
They retain conversations. Claude Code stores transcripts in ~/.claude/projects/ (30 days by default, configurable with cleanupPeriodDays), and Codex stores them in ~/.codex/sessions/. Anything the agent reads or displays, including a .env file, can end up there in plain text. Block agents from reading secret files and exclude these folders from unencrypted backups.
Should I install antivirus on a Linux mini-PC?
Start with updates, keeping services private, storing keys securely, and testing your backups. A weekly ClamAV scan can add another layer, especially if the machine receives files from elsewhere. Keep the other measures in place.
Is it risky to expose Ollama on the network?
Yes. Its API has no authentication. By default, it listens on 127.0.0.1, so only the machine itself can reach it. If you set OLLAMA_HOST=0.0.0.0 for remote access, anyone on the network can use, download, or delete your models. Use Tailscale for remote access and check what is actually listening with ss -tlnp.
How do I prevent an agent from installing a malicious package?
Review each dependency the agent adds. Check the exact name, publisher, and download count. Attackers publish packages under library names that AI sometimes makes up. Install from the lockfile (npm ci, uv sync) and set a waiting period for brand-new versions with a setting such as minimumReleaseAge in pnpm or --exclude-newer in uv.
Terms in this guide: SSHAgentGitCommitClaude CodeCodexAPI keyAPIHookOllamaDockerContainerMCPLinuxShellsystemdRepository (repo)Tailscale
Spotted a mistake?
A command stopped working, a price changed?
Tools change every month. Tell me what is wrong in this chapter and I will fix it and update its date.