/kamal-skills:server-hardeningfrom kamal-skills
Inspect a Linux server Kamal deploys to and harden it — automated security updates, firewall/port lockdown, auto-blocking of repeated SSH auth failures, and safe SSH configuration — while keeping the ports Kamal needs open. Use when the user says "harden my server," "lock down my VPS," "secure my Kamal server," "audit server security," "close open ports," "set up automatic updates," "is my server exposed to the internet," or before putting a new box into production. Interviews the user before changing anything, explains how to undo every change, and verifies the result afterward. For provisioning Docker itself, see setup. For the servers/roles Kamal targets, see servers. For the SSH settings Kamal itself uses to connect, see ssh. For accessory port exposure, see accessories.
Ships in kamal-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
You are an expert in hardening Linux servers that run Kamal deployments. Your goal is to reduce a server's exposure to the public internet — without breaking the access Kamal itself needs (SSH, and the ports kamal-proxy publishes) or locking the user out of their own box.
PermitRootLogin, confirm key-based login works for the account Kamal (and the user) will keep using — and keep a second, already-connected SSH session open until the new settings are verified. If that session drops before verification, the user may be locked out for good.Read what already exists before asking questions:
config/deploy.yml — servers: (which hosts), ssh: (user, port — default root/22), and any accessories: port: bindings. A binding like "5432:5432" is exposed on every interface; "127.0.0.1:5432:5432" is not — see the accessories skill.servers:, or ask directly if this isn't a Kamal-managed box yet.Run scripts/inspect.sh on the target server. It only reads state — it changes nothing. It reports:
ss -tulpn)sshd settings: PermitRootLogin, PasswordAuthentication, Portfail2ban is installed and runningunattended-upgrades / dnf-automatic)ssh root@your-server 'bash -s' < skills/server-hardening/scripts/inspect.sh
Summarize the findings for the user in a few lines before moving on — don't dump raw output.
Ask before deciding anything. Use a structured question tool if your environment provides one (for example, AskUserQuestion in Claude Code); otherwise ask these directly in the conversation:
80 and 443 open. Are there any other ports that must stay open (a non-Kamal service, a direct database connection)? Cross-check against any accessories: port bindings found in Step 1.root (the default) or a non-root user (ssh: user: in config/deploy.yml)? Whichever it is, that account's key-based login must be confirmed working before anything else is restricted.PermitRootLogin? Only if Kamal is configured to deploy as a non-root user and that user already has working sudo + Docker group access (see the ssh skill's non-root bootstrap steps).Before running anything that changes state, show the user a concrete list: each change, the exact command, and the exact command to undo it. Don't fold this into Step 2 — the interview picks the what, this confirms exactly this, in this order. Wait for an explicit yes before Step 4.
Back up any file before editing it:
sudo cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%Y%m%d%H%M%S)
Apply only the categories the user approved, in this order — updates and fail2ban first (low risk), firewall next, SSH last (highest risk of lockout):
| Category | Reference |
|---|---|
| Automated security updates | references/automatic-updates.md |
| fail2ban | references/ssh-hardening.md |
| Firewall / port lockdown | references/firewall.md |
| SSH hardening (password auth, root login, port) | references/ssh-hardening.md |
Each reference gives the command and its undo side by side. Apply SSH changes last, and test in a second, separate terminal before closing the session you're working in.
Docker owns its own firewall rules. kamal-proxy's ports are published through Docker, and Docker inserts its own rules ahead of ufw/firewalld's — a ufw
denyalone will not necessarily block a port Docker has published. See references/firewall.md before assuming a rule took effect.
Run scripts/verify.sh on the server, ideally from a session other than the one used to make changes:
ssh root@your-server 'bash -s' < skills/server-hardening/scripts/verify.sh 22 80 443
It checks both directions:
sshd effective config matches what was approved; the fail2ban service is active if installed; the auto-update timer is enabled if configured.The script only proves ports are open on loopback — have the user confirm real external reachability from their own machine (nc -zv <server-ip> 443) and a fresh login (not the session that made the changes) before calling this done.
Every change in Step 4 has a paired undo command in the references above; see references/rollback.md for the consolidated table. The short version: restore the timestamped backup and reload/restart the affected service; apt remove/systemctl disable anything newly installed.
kamal setup — do this before hardening a fresh box.servers:/roles list that tells you which hosts to harden.ssh: block Kamal itself uses to connect — must stay in sync with any SSH hardening here.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub donnfelker/kamal-skills --plugin kamal-skills25 skills in this plugin
/accessoriesRun and manage accessory services — databases, Redis, search, and other long-lived dependencies your app needs — through Kamal's `accessories:` configuration and the `kamal accessory` command. Use this when the user says things like "add a MySQL/Postgres/Redis accessory," "run a database with Kamal," "kamal accessory boot," "set up a sidecar/companion service," "my app needs a cache or search container," "persist accessory data with volumes," or "reboot/restart/remove an accessory." Covers defining the accessory (image, host/hosts/role/roles/tag/tags, port, env, files, directories, volumes, network, options, registry, proxy) and operating it with boot, reboot, restart, start, stop, details, logs, exec, and remove. For passing configuration and credentials into accessories, see env and secrets. For scheduled jobs, see cron./aliasesDefine custom command aliases under the top-level `aliases` key in `config/deploy.yml` so a long, repeated `kamal` invocation becomes a single `kamal <name>`. Use it when the user says "add a Kamal alias," "shortcut kamal app exec," "make `kamal console` open a Rails console," "create a one-liner to deploy staging," "I keep retyping the same kamal command," or asks about the `aliases` config key, alias naming rules, or a `deploy -d staging` shortcut. Covers how an alias expands into a `kamal` subcommand, the lowercase letters/numbers/dashes/underscores naming rule, and the documented examples `console: app exec -i --reuse "bin/rails console"`, `uname: app exec -p -q -r web "uname -a"`, and `staging_deploy: deploy -d staging`. For the rest of `config/deploy.yml` and DRYing it up with YAML anchors, see config. For the underlying app exec / console / logs commands the aliases wrap, see app./appOperate and inspect already-running Kamal apps without redeploying. Manage app containers with `kamal app` (boot, start, stop, containers, details, images, version, logs, exec, remove, stale_containers), set maintenance/live mode (`kamal app maintenance --message`, `kamal app live`, `error_pages_path`), see every container with `kamal details`, review what ran on each server with `kamal audit`, print the resolved config with `kamal config`, run one-off and interactive commands with `kamal app exec` (`--primary/-p`, `--interactive/-i`, `--reuse`, `--raw`), and check the installed CLI version with `kamal version`. Use when the user says "boot/start/stop the app," "show running containers," "exec into the app," "open a Rails console," "run a command on all servers," "put the app in maintenance mode," "show the audit log," or "print my Kamal config." For shipping releases, see deploy. For reverting a release, see rollback. For log-driver and OTel/file config, see logging. For kamal-proxy, see proxy./buildConfigure Kamal builders and build then push your app image. Use this skill when the user wants to set up the `builder` block in config/deploy.yml — choosing local, remote, multi-arch, or Docker Build Cloud builds, picking a `driver`, passing build `args`, build `secrets`, or `cache`, switching the `dockerfile`, `context`, or `target`, or building without a Dockerfile via buildpacks (`pack`) — and when they want to run `kamal build push`, `kamal build dev`, or other `kamal build` subcommands. Trigger phrases include "kamal build," "build my image," "push the image to the registry," "build for amd64/arm64," "remote builder," "Apple Silicon cross-build is slow," "speed up my builds with cache," "pass a build arg," "use a build secret," or "build without a Dockerfile." For configuring the container registry, see registry. For the one-step flow that builds and ships in a single command, see deploy. For managing the secret values that build secrets reference, see secrets./ci-deploySet up continuous deployment so every push to main runs `kamal deploy` from GitHub Actions once the tests pass — for any stack Kamal ships (Rails, Next.js, Phoenix, Rust, static sites, and more). Use when the user says "auto-deploy on push," "deploy from GitHub Actions," "continuous deployment with Kamal," "deploy when CI passes," "set up CD," "stop deploying from my laptop," or "use 1Password in GitHub Actions." Covers the deploy ssh key, secrets in a GitHub environment or read from 1Password with a service account, the workflow, the GHA build cache, and verifying the first run. For running a deploy by hand, see deploy. For the secrets file itself, see secrets. For build cache options, see build./configUnderstand and write your Kamal configuration in config/deploy.yml. Use when the user says "set up config/deploy.yml," "what goes in my deploy.yml," "what are the required keys," "add a staging destination," "deploy with -d staging," "DRY up my config with YAML anchors," "what does retain_containers / readiness_delay / primary_role / deploy_timeout do," "kamal init," or "kamal config." Covers the required service and image keys, destinations (-d) and merged per-destination files, x- extensions, every top-level option and its default, and reusing config with anchors and aliases. For configuring servers and roles, see servers. For env and secrets, see env. For command shortcuts, see aliases. For a first deployment, see setup.