Improved SSH known_hosts error handling. Added error codes file.

This commit is contained in:
Raphaël Numbus
2026-05-29 15:47:16 +02:00
parent 91d90be2a9
commit 514d13d8ff
2 changed files with 35 additions and 16 deletions
+32 -16
View File
@@ -93,6 +93,37 @@ hierarchy_preparation() {
echod "\n ✅ Folder hierarchy ready"
}
setup_ssh() {
echod "\n ➡️ Generating new SSH key for numbus-admin..."
chmod 700 "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/"
ssh-keygen -t "ed25519" -C "numbus-admin@numbus-${DEVICE_TYPE}" -f "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/id_ed25519" -N "" -q
echod "\n ➡️ Copying SSH key to target host '${TARGET_USER}@${LIVE_TARGET_IP}'..."
if cat "~/.ssh/known_hosts" | grep ${LIVE_TARGET_IP}; 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\"").
This could occur for multiple reasons :
- You ran the script multiple times and rebooted your live machine
- 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
The script $(gum style --bold "cannot continue") without the correct fingerprint installed.\n"
gum confirm "Remove the old fingerprint and accept the new one ?" || { echo -e "\n\n ❌ Exiting."; exit 22; }
sed -i '/${LIVE_TARGET_IP}/d' "~/.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
}
hardware_detection() {
local TMPFILE="/run/user/1000/numbus-installer/hw_detection.json"
@@ -371,22 +402,6 @@ launch_gui() {
# --- MAIN SCRIPT FUNCTIONS --->
setup_ssh() {
echod "\n ✅ Generating new SSH key for numbus-admin..."
chmod 700 "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/"
ssh-keygen -t "ed25519" -C "numbus-admin@numbus-${DEVICE_TYPE}" -f "${TMP_EXTRA_PATH}/home/numbus-admin/.ssh/id_ed25519" -N "" -q
echod "\n ➡️ Copying SSH key to target host '${TARGET_USER}@${LIVE_TARGET_IP}'..."
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
}
server_config_generation() {
echod "\n 📝 Generating structured settings.json..."
@@ -773,6 +788,7 @@ PORT_REGEX='^[0-9]{1,5}$'
SSH_KEY_REGEX='^ssh-[a-z0-9]+ [A-Za-z0-9+/]+.*'
PHONE_REGEX='^\+[1-9][0-9]{7,14}$'
FOREGROUND="212"
GUM_INPUT_PADDING="1 1"
GUM_INPUT_HEADER_FOREGROUND="212"
GUM_INPUT_CURSOR_FOREGROUND="212"
+3
View File
@@ -0,0 +1,3 @@
0: successful.
1: error.
22: SSH fingerprint in `known_hosts` for the IP is different than the current one.