feat: root adds the ssh keys, mkosi ssh for the test VM

The setup no longer asks for an ssh key. Root logs in on the console and
adds keys for claude and root to /var/lib/agent. Root may log in with
ssh, and its home is a tmpfs that is wiped at every boot. The test VM
uses mkosi ssh instead of a forwarded port, so the agent.ssh-key
credential is gone.

Also mount /var with noatime, move STYLE.md into AGENTS.md and rewrite
comments to start with the name of what they describe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-19 19:10:54 +01:00
1 parent 8aeb448936
commit db8fb0d5a4
15 files changed
+218 -180

No files matched your search

+8 -2
View File
@@ -1,5 +1,11 @@
# Mounts
#
# /var is the only partition on disk that is written (mkosi.repart/30-var.conf).
# x-systemd.growfs grows its filesystem to fill the partition at boot.
PARTLABEL=var /var ext4 x-systemd.growfs 0 2
# x-systemd.growfs grows its filesystem to fill the partition at boot. noatime
# skips the write that the default (relatime) makes at the first read of a file
# each day. Images that podman unpacks are full of such files; nothing here uses
# access times.
PARTLABEL=var /var ext4 noatime,x-systemd.growfs 0 2
# /root is in memory, so root has a writable home that is wiped at every boot.
# Root's ssh key lives on /var (mkosi.extra/etc/ssh/sshd_config.d).
tmpfs /root tmpfs mode=0700 0 0
@@ -1,11 +1,22 @@
# ssh login
#
# Only the user claude may log in, only with the key asked at setup. The host
# key lives on /var (agent-boot makes it), so it stays the same across reboots.
# The first value wins, and this file sorts before Fedora's 50-redhat.conf.
# Login is with keys only, for root and the user claude. Neither has a key
# until root adds one (README.md). The first value wins, and this file sorts
# before Fedora's 50-redhat.conf.
# HostKey lives on /var (agent-boot makes it), so it stays the same across
# reboots.
HostKey /var/lib/agent/ssh_host_ed25519_key
AuthorizedKeysFile /var/lib/agent/authorized_keys
AllowUsers claude
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
# AuthorizedKeysFile of the user claude is owned by root, so Claude can't add
# keys.
Match User claude
AuthorizedKeysFile /var/lib/agent/authorized_keys
# AuthorizedKeysFile of root is on /var, because its home is wiped at every
# boot (/etc/fstab). It also reads the default file, which the
# ssh.authorized_keys.root credential fills, such as for mkosi ssh.
Match User root
AuthorizedKeysFile /var/lib/agent/root_authorized_keys .ssh/authorized_keys
@@ -10,5 +10,6 @@ Kind=!*
DHCP=yes
[DHCPv4]
# The hostname is the one asked at setup (agent-boot), not the DHCP server's.
# UseHostname=no keeps the hostname asked at setup (agent-boot) instead of the
# DHCP server's.
UseHostname=no
@@ -6,8 +6,8 @@
enable systemd-networkd.service
enable systemd-resolved.service
enable sshd.service
# Fedora disables the login on the screen (tty1, and tty2-6 through its
# autovt@ alias).
# getty@.service is the login on the screen, which Fedora disables (tty1, and
# tty2-6 through its autovt@ alias).
enable getty@.service
enable agent-setup@.service tty1 ttyS0
enable etc-shadow.mount
@@ -15,8 +15,8 @@ enable agent-boot.service
enable claude-remote.path
enable systemd-sysupdate-update.timer
enable systemd-sysupdate-reboot.timer
# Fedora enables these, but they do nothing here: no PAM or crypto changes on a
# read-only /etc, and no system or config extensions.
# These services do nothing here, but Fedora enables them: no PAM or crypto
# changes on a read-only /etc, and no system or config extensions.
disable authselect-apply-changes.service
disable fips-crypto-policy-overlay.service
disable systemd-sysext.service
@@ -18,7 +18,7 @@ StandardOutput=tty
TTYPath=/dev/%I
TTYReset=yes
TTYVHangup=yes
# Being stopped by the other console is not a failure.
# SuccessExitStatus counts being stopped by the other console as success.
SuccessExitStatus=SIGTERM
[Install]
@@ -11,7 +11,8 @@ After=network-online.target user@1000.service agent-boot.service
[Service]
User=claude
WorkingDirectory=~
Environment=CLAUDE_CONFIG_DIR=/var/lib/agent/claude XDG_RUNTIME_DIR=/run/user/1000
EnvironmentFile=/etc/environment
Environment=XDG_RUNTIME_DIR=/run/user/1000
ExecStart=/usr/bin/claude remote-control --name %H
Restart=always
RestartSec=10s
+6 -5
View File
@@ -3,13 +3,14 @@
# What survives a reboot and what doesn't. Claude can only write to the wiped
# directories, /tmp and its own config.
# Kept: the setup answers, the ssh host key and Claude's login. agent-boot
# wipes the rest of Claude's config.
# /var/lib/agent keeps the setup answers, the ssh keys and Claude's login.
# agent-boot wipes the rest of Claude's config.
d /var/lib/agent 0755 root root -
d /var/lib/agent/claude 0700 claude claude -
# Wiped at every boot (D): Claude's home, with its podman storage, and
# temporary files.
# D wipes Claude's home, with its podman storage, and temporary files at every
# boot.
D /var/home/claude 0700 claude claude -
D /var/tmp 1777 root root -
# Start Claude's user manager at boot, for rootless podman and its own services.
# linger starts Claude's user manager at boot, for rootless podman and its own
# services.
f /var/lib/systemd/linger/claude
+22 -15
View File
@@ -1,24 +1,25 @@
#!/bin/bash
# First-boot setup
#
# Asks for the root password, the hostname and the ssh key of the user claude
# (agent-setup@.service). /etc is read-only, so the answers go to
# /var/lib/agent. The password goes into a shadow file there, which
# etc-shadow.mount puts over /etc/shadow. agent-boot applies the rest at every
# boot.
# Asks for the root password and the hostname (agent-setup@.service). /etc is
# read-only, so the answers go to /var/lib/agent. The password goes into a
# shadow file there, which etc-shadow.mount puts over /etc/shadow. agent-boot
# applies the rest at every boot. Root adds the ssh keys afterwards
# (README.md).
#
# With the credential agent.password, it asks nothing and takes the answers
# from the credentials agent.password, agent.hostname and agent.ssh-key. mkosi
# vm passes them (mkosi.conf).
# from the credentials agent.password and agent.hostname. mkosi vm passes them
# (mkosi.conf).
set -euo pipefail
# cred prints the credential agent.<name>, and fails if it isn't passed.
cred() { cat "${CREDENTIALS_DIRECTORY:-/nonexistent}/agent.$1" 2>/dev/null; }
if pw=$(cred password); then
# Both consoles run this script. Only one may do the setup.
# flock lets only one of the two consoles do the setup.
exec 9>/run/agent-setup.lock
flock -n 9 || exit 0
name=$(cred hostname) || true
key=$(cred ssh-key) || true
else
echo "== Agent setup =="
while :; do
@@ -28,18 +29,24 @@ else
echo "Passwords do not match, try again."
done
read -rp "Hostname [agent]: " name
read -rp "SSH public key for the user claude: " key
fi
install -d -m 0700 /var/lib/agent/etc
# etc-shadow.mount is stopped first: an interrupted setup may have started it,
# and then cp would copy the shadow file onto itself.
systemctl stop etc-shadow.mount
cp /etc/passwd /etc/shadow /var/lib/agent/etc/
echo "root:$pw" | chpasswd --prefix /var/lib/agent
systemctl start etc-shadow.mount
[[ -n $key ]] && install -m 0644 /dev/stdin /var/lib/agent/authorized_keys <<<"$key"
# Written last: its presence marks the setup as done.
# hostname is written last: its presence marks the setup as done.
echo "${name:-agent}" > /var/lib/agent/hostname
systemctl start agent-boot.service sshd.service
echo "Done. Log in with ssh claude@<this VM>, run claude and log in with your account."
echo "Remote Control then starts by itself."
# Stop the setup on the other console, which then shows its login.
cat <<'EOF'
Done. Log in as root and add your ssh key for the user claude to
/var/lib/agent/authorized_keys (for root: root_authorized_keys there). Then
log in with ssh claude@<this VM>, run claude and log in with your account.
Remote Control then starts by itself.
EOF
# systemctl stop ends the setup on the other console, which then shows its
# login.
systemctl --no-block stop "agent-setup@*.service"