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

+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"