Improved the SSH error handling.
This commit is contained in:
+11
-13
@@ -117,11 +117,15 @@ setup_ssh() {
|
||||
|
||||
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
|
||||
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\"").
|
||||
while true; do
|
||||
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 :
|
||||
- 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
|
||||
- You are under a Man-In-The-Middle attack
|
||||
- Other
|
||||
@@ -129,16 +133,10 @@ setup_ssh() {
|
||||
The script $(gum style --bold "cannot continue") without the correct fingerprint installed.
|
||||
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; }
|
||||
sed -i '/${LIVE_TARGET_IP}/d' "/home/${USER}/.ssh/known_hosts"
|
||||
fi
|
||||
|
||||
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
|
||||
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"
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
hardware_detection() {
|
||||
|
||||
Reference in New Issue
Block a user