Skip to content

Commit

Permalink
Switch to root user if non-root user is used for nixos installer
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Mar 23, 2024
1 parent c34fd21 commit 52f932b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ if [[ -n ${ssh_private_key_file-} ]]; then
fi

ssh_settings=$(ssh "${ssh_args[@]}" -G "${ssh_connection}")
ssh_user=$(echo "$ssh_settings" | awk '/^user / { print $2 }')
ssh_host=$(echo "$ssh_settings" | awk '/^hostname / { print $2 }')
ssh_port=$(echo "$ssh_settings" | awk '/^port / { print $2 }')

Expand Down Expand Up @@ -411,6 +412,14 @@ SSH
# waiting for machine to become available again
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
fi

# Installation will fail if non-root user is used for installer.
# Switch to root user by copying authorized_keys.
if [[ ${is_installer-n} == "y" ]] && [[ ${ssh_user} != "root" ]]; then
ssh_ "${maybe_sudo} mkdir -p /root/.ssh; ${maybe_sudo} cp ~/.ssh/authorized_keys /root/.ssh"
ssh_connection="root@${ssh_host}"
fi

for path in "${!disk_encryption_keys[@]}"; do
step "Uploading ${disk_encryption_keys[$path]} to $path"
ssh_ "umask 077; cat > $path" <"${disk_encryption_keys[$path]}"
Expand Down

0 comments on commit 52f932b

Please sign in to comment.