chore: Improve ssh key copy process and remote communication

This commit is contained in:
Enrico Ludwig 2024-05-14 12:07:35 +02:00
parent 8431ced241
commit 094fc441e1

View File

@ -45,7 +45,7 @@ BORGMATIC_CONFIG_FILE="/etc/borgmatic/config.yaml" # Path to the borgmatic confi
SSH_HOST="127.0.0.1" # Hostname or IP address of the backup server SSH_HOST="127.0.0.1" # Hostname or IP address of the backup server
SSH_PORT="22" # SSH port of the backup server (default: 22) SSH_PORT="22" # SSH port of the backup server (default: 22)
SSH_USER="root" # SSH user on the backup server SSH_USER="root" # SSH user on the backup server
SSH_PASSWORD="12345678" # Only required for ssh-copy-id SSH_PASSWORD="12345678" # Only required for copying the ssh key to the backup server
SSH_KEY_NAME="borgmatic" SSH_KEY_NAME="borgmatic"
SSH_KEY_TYPE="ed25519" # SSH key type (e.g. rsa, dsa, ecdsa, ed25519), default: ed25519 SSH_KEY_TYPE="ed25519" # SSH key type (e.g. rsa, dsa, ecdsa, ed25519), default: ed25519
SSH_KEY_FILE="/root/.ssh/${SSH_KEY_NAME}_${SSH_KEY_TYPE}" SSH_KEY_FILE="/root/.ssh/${SSH_KEY_NAME}_${SSH_KEY_TYPE}"
@ -686,7 +686,7 @@ 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 sshpass -p "$SSH_PASSWORD" ssh-copy-id -i "$SSH_KEY_FILE" -p "$SSH_PORT" -oStrictHostKeyChecking=no -oBatchMode=yes "$SSH_USER@$SSH_HOST"; then 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
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."