Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support non-interactive password authentication with sshpass #305

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ below.
6. On the target machine, make sure you have access as root via ssh by adding
your SSH key to the file `authorized_keys` in the directory `/root/.ssh`

Optionally, bootstrapping can also be performed through password login. For
example through the `image-installer-*` provided by
`nix-community/nixos-images`. Assign your password to the `SSH_PASS`
environment variable and specify `--env-password` as an additional command
line option. This will provide `ssh-copy-id` with the required password.

7. (Optional) Test your nixos and disko configuration:

The following command will automatically test your nixos configuration and
Expand Down
2 changes: 2 additions & 0 deletions src/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
, gawk
, findutils
, gnused
, sshpass
, terraform-docs
, lib
, makeWrapper
Expand All @@ -26,6 +27,7 @@ let
gawk
findutils
gnused # needed by ssh-copy-id
sshpass # used to provide password for ssh-copy-id
rsync # used to upload extra-files
];
in
Expand Down
35 changes: 27 additions & 8 deletions src/nixos-anywhere.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ Options:
set an ssh option
* -L, --print-build-logs
print full build logs
* --env-password
set a password used by ssh-copy-id, the password should be set by
the environment variable SSH_PASS
* -s, --store-paths <disko-script> <nixos-system>
set the store paths to the disko-script and nixos-system directly
if this is give, flake is not needed
Expand Down Expand Up @@ -162,6 +165,9 @@ while [[ $# -gt 0 ]]; do
--build-on-remote)
build_on_remote=y
;;
--env-password)
env_password=y
;;
--vm-test)
vm_test=y
;;
Expand Down Expand Up @@ -288,14 +294,27 @@ ssh_port=$(echo "$ssh_settings" | awk '/^port / { print $2 }')

step Uploading install SSH keys
until
ssh-copy-id \
-i "$ssh_key_dir"/nixos-anywhere.pub \
-o ConnectTimeout=10 \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
"${ssh_copy_id_args[@]}" \
"${ssh_args[@]}" \
"$ssh_connection"
if [[ -n ${env_password-} ]]; then
sshpass -e \
ssh-copy-id \
-i "$ssh_key_dir"/nixos-anywhere.pub \
-o ConnectTimeout=10 \
-o UserKnownHostsFile=/dev/null \
-o IdentitiesOnly=yes \
-o StrictHostKeyChecking=no \
"${ssh_copy_id_args[@]}" \
"${ssh_args[@]}" \
"$ssh_connection"
else
ssh-copy-id \
-i "$ssh_key_dir"/nixos-anywhere.pub \
-o ConnectTimeout=10 \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
"${ssh_copy_id_args[@]}" \
"${ssh_args[@]}" \
"$ssh_connection"
fi
do
sleep 3
done
Expand Down
Loading