aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKumar Damani <me@kumardamani.net>2026-09-12 20:28:49 +0000
committerKumar Damani <me@kumardamani.net>2026-09-12 20:28:49 +0000
commit30a110b603749f62c88641c2a36e988f21c32552 (patch)
tree5833eda0417f452bb4e340a632ce06c0f2a7f75e
parent2ddb7f291f5ceb47dcbdeb79158c10ce563ee391 (diff)
fixed priv. escalation race on first deploy
-rwxr-xr-xnix/deploy.sh13
1 files changed, 8 insertions, 5 deletions
diff --git a/nix/deploy.sh b/nix/deploy.sh
index 4459aab..98e48d0 100755
--- a/nix/deploy.sh
+++ b/nix/deploy.sh
@@ -8,6 +8,7 @@ HOST="$1"
FLAKE=".#${HOST}"
KEY_DIR="./host-keys/${HOST}"
USER="${2:-root}"
+TARGET="${3:-switch}"
# Validate
if [ ! -d "$KEY_DIR" ]; then
@@ -34,10 +35,12 @@ if [ "$LOCAL_FINGERPRINT" != "$REMOTE_FINGERPRINT" ]; then
echo " Remote: ${REMOTE_FINGERPRINT}"
# Copy the pre-generated key to replace the VM's auto-generated one
- scp "${KEY_DIR}/ssh_host_ed25519_key" "${USER}@${HOST}:/etc/ssh/ssh_host_ed25519_key"
- scp "${KEY_DIR}/ssh_host_ed25519_key.pub" "${USER}@${HOST}:/etc/ssh/ssh_host_ed25519_key.pub"
- ssh "${USER}@${HOST}" chmod 600 /etc/ssh/ssh_host_ed25519_key
- ssh "${USER}@${HOST}" chmod 644 /etc/ssh/ssh_host_ed25519_key.pub
+ scp "${KEY_DIR}/ssh_host_ed25519_key" "${USER}@${HOST}:/tmp/ssh_host_ed25519_key"
+ scp "${KEY_DIR}/ssh_host_ed25519_key.pub" "${USER}@${HOST}:/tmp/ssh_host_ed25519_key.pub"
+ ssh "${USER}@${HOST}" sudo cp /tmp/ssh_host_ed25519_key /etc/ssh/ssh_host_ed25519_key
+ ssh "${USER}@${HOST}" sudo cp /tmp/ssh_host_ed25519_key.pub /etc/ssh/ssh_host_ed25519_key.pub
+ ssh "${USER}@${HOST}" sudo chmod 600 /etc/ssh/ssh_host_ed25519_key
+ ssh "${USER}@${HOST}" sudo chmod 644 /etc/ssh/ssh_host_ed25519_key.pub
echo "→ [${HOST}] Key replaced. You may get a WARNING on next SSH (host key changed)."
echo " Remove old key with: ssh-keygen -R ${HOST}"
@@ -47,7 +50,7 @@ fi
# Deploy
echo "→ [${HOST}] Deploying with nixos-rebuild..."
-nixos-rebuild switch \
+nixos-rebuild "$TARGET" \
--flake "$FLAKE" \
--target-host "${USER}@${HOST}" \
--sudo