From e7f35226716ca252afae3254e10549168242f879 Mon Sep 17 00:00:00 2001 From: Tero Date: Wed, 2 Sep 2026 00:18:04 +0300 Subject: [PATCH] Some fixes for non woring sudo --- README.md | 4 ++++ zfs-move-over-ssh.sh | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8b9a39a..792550f 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,10 @@ If this command fails, configure the remote account's `sudoers` entry for the necessary `zfs` commands with `NOPASSWD` before running the migration. Do not put a password in the script or on its command line. +`REMOTE_HOST` must be a complete hostname or address, such as +`root@192.0.2.10` or `admin@new-server`. `root@` is invalid because it has no +host after the `@`. + Options: | Option | Description | diff --git a/zfs-move-over-ssh.sh b/zfs-move-over-ssh.sh index e042c11..a651470 100644 --- a/zfs-move-over-ssh.sh +++ b/zfs-move-over-ssh.sh @@ -83,14 +83,18 @@ REMOTE_HOST="$2" DESTINATION_ROOT="${3%/}" SNAPSHOT_NAME="move-$(date +%Y%m%d-%H%M%S)" +[[ "$REMOTE_HOST" != *@ ]] || die "REMOTE_HOST is missing a hostname; use user@server-name or server-name" + command -v zfs >/dev/null || die "zfs command was not found" command -v zpool >/dev/null || die "zpool command was not found" command -v ssh >/dev/null || die "ssh command was not found" zpool list -H -o name "$SOURCE_POOL" >/dev/null || die "source pool does not exist: $SOURCE_POOL" if ! $DRY_RUN; then + ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" true \ + || die "cannot authenticate to $REMOTE_HOST with SSH keys or an SSH agent" ssh "${SSH_OPTIONS[@]}" "$REMOTE_HOST" 'sudo -n zfs list -H -o name -t filesystem >/dev/null' \ - || die "cannot connect with non-interactive SSH or run 'sudo -n zfs' on $REMOTE_HOST" + || die "$REMOTE_HOST accepts SSH, but cannot run 'sudo -n zfs'; configure passwordless sudo for zfs" fi map_destination() {