Ask for ssh password before the actual communication starts

This commit is contained in:
Enrico Ludwig 2024-05-14 12:09:25 +02:00
parent 094fc441e1
commit a1a67eca33

View File

@ -675,8 +675,6 @@ if ! inf_follow "Checking for default ssh key at $SSH_KEY_FILE..." "\e[1;32mYes\
fi fi
fi 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
# ask for ssh password if none is set # ask for ssh password if none is set
if [ -z "$SSH_PASSWORD" ]; then if [ -z "$SSH_PASSWORD" ]; then
wrn "Please enter the password for the ssh key to copy it to the backup server." wrn "Please enter the password for the ssh key to copy it to the backup server."
@ -686,7 +684,9 @@ if ! inf_follow "Checking if ssh key is already present on $SSH_HOST..." "\e[1;3
echo "" echo ""
fi fi
if ! inf_follow "Copying ssh key to $SSH_HOST..." "\e[1;32mOK\e[0m" "\e[1;31mFAILED\e[0m" run_command sudo 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 # 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
err "Failed to copy ssh key to $SSH_HOST." err "Failed to copy ssh key to $SSH_HOST."
err "Please validate your ssh password and and host settings and try again." 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." err "If the error persists, please contact the support at $SCRIPT_SUPPORT."