From a83b79ff8655695cbb6fb6d1a06ad4998f901257 Mon Sep 17 00:00:00 2001 From: Enrico Ludwig Date: Tue, 14 May 2024 12:39:45 +0200 Subject: [PATCH] Copying ssh key needs to be run in a separate bash shell to be able to access the borgmatic ssh key of root --- borgmatic_setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/borgmatic_setup.sh b/borgmatic_setup.sh index dd80365..51e2a43 100755 --- a/borgmatic_setup.sh +++ b/borgmatic_setup.sh @@ -686,7 +686,7 @@ fi # check first if ssh key is already present on the remote end if ! inf_follow "Checking if ssh key is already present on $SSH_HOST..." "\e[1;32mYes\e[0m" "\e[1;31mNo\e[0m" run_command ssh -oStrictHostKeyChecking=no -oBatchMode=yes -i "$SSH_KEY_FILE" -p "$SSH_PORT" -l "$SSH_USER" "$SSH_HOST" exit; then - if ! inf_follow "Copying ssh key to $SSH_HOST..." "\e[1;32mOK\e[0m" "\e[1;31mFAILED\e[0m" run_command sshpass -p "$SSH_PASSWORD" ssh -oStrictHostKeyChecking=no -oBatchMode=yes -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < "$SSH_KEY_FILE"; then + if ! inf_follow "Copying ssh key to $SSH_HOST..." "\e[1;32mOK\e[0m" "\e[1;31mFAILED\e[0m" run_command sudo bash -c "sshpass -p '$SSH_PASSWORD' ssh -oStrictHostKeyChecking=no -oBatchMode=yes -p '$SSH_PORT' '$SSH_USER@$SSH_HOST' 'mkdir -p .ssh && cat >> .ssh/authorized_keys' < '$SSH_KEY_FILE'"; then err "Failed to copy ssh key to $SSH_HOST." err "Please validate your ssh password and and host settings and try again." err "If the error persists, please contact the support at $SCRIPT_SUPPORT."