Improved the SSH error handling.

This commit is contained in:
Raphaël Numbus
2026-05-29 16:10:59 +02:00
parent 92e0f077a4
commit 39104ecf92
+11 -13
View File
@@ -117,11 +117,15 @@ setup_ssh() {
echod "\n ➡️ Copying SSH key to target host '${TARGET_USER}@${LIVE_TARGET_IP}'..." echod "\n ➡️ Copying SSH key to target host '${TARGET_USER}@${LIVE_TARGET_IP}'..."
if cat "/home/${USER}/.ssh/known_hosts" | grep "${LIVE_TARGET_IP}" >> "${STDOUT}" 2>> "${STDERR}"; then while true; do
echo -e "\n ⚠️ The SSH fingerprint for the selected IP address $(gum style --italic "\"${LIVE_TARGET_IP}\"") is not the same as the one in $(gum style --italic "\".ssh/known_hosts\""). if sshpass -p "${LIVE_TARGET_PASSWORD}" ssh-copy-id -o StrictHostKeyChecking=no -i "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/id_ed25519" "${TARGET_USER}@${LIVE_TARGET_IP}" >> "${STDOUT}" 2>> "${STDERR}"; then
echod "\n ✅ SSH key copied successfully"
break
else
echo -e "\n ⚠️ The SSH fingerprint for the selected IP address $(gum style --italic "\"${LIVE_TARGET_IP}\"") is not the same as the one in $(gum style --italic "\".ssh/known_hosts\"").
This could occur for multiple reasons : This could occur for multiple reasons :
- You ran the script multiple times and rebooted your live machine - You ran this script multiple times
- Your live machine uses an IP address that was used by another devices you SSHed in - Your live machine uses an IP address that was used by another devices you SSHed in
- You are under a Man-In-The-Middle attack - You are under a Man-In-The-Middle attack
- Other - Other
@@ -129,16 +133,10 @@ setup_ssh() {
The script $(gum style --bold "cannot continue") without the correct fingerprint installed. The script $(gum style --bold "cannot continue") without the correct fingerprint installed.
If you are unsure, it is always better to check manually.\n" If you are unsure, it is always better to check manually.\n"
gum confirm "Remove the old fingerprint and accept the new one ?" || { echo -e "\n\n ❌ SSH fingerprints don't match."; exit 22; } gum confirm "Remove the old fingerprint and accept the new one ?" || { echo -e "\n\n ❌ SSH fingerprints don't match."; exit 22; }
sed -i '/${LIVE_TARGET_IP}/d' "/home/${USER}/.ssh/known_hosts" sed -i "/${LIVE_TARGET_IP}/d" "/home/${USER}/.ssh/known_hosts"
fi fi
done
if sshpass -p "${LIVE_TARGET_PASSWORD}" ssh-copy-id -o StrictHostKeyChecking=no -i "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/id_ed25519" "${TARGET_USER}@${LIVE_TARGET_IP}" >> "${STDOUT}" 2>> "${STDERR}"; then
echod "\n ✅ SSH key copied successfully"
else
echo -e "\n ❌ Failed to copy SSH key. Please check the host IP and password."
exit 1
fi
} }
hardware_detection() { hardware_detection() {