Fix SSH root login password issue for installed system

- Add default root password 'mbetter123' when no preseed password provided
- Improve password setting logic with better error handling and logging
- Ensure root account is properly unlocked and password never expires
- Add debugging output to track password setting process
- Fix 'password check failed' error by guaranteeing password is set
parent e34833bd
...@@ -540,21 +540,34 @@ configure_target_system() { ...@@ -540,21 +540,34 @@ configure_target_system() {
mount -o bind /dev "$TARGET_MOUNT/dev" mount -o bind /dev "$TARGET_MOUNT/dev"
mount -t devpts devpts "$TARGET_MOUNT/dev/pts" mount -t devpts devpts "$TARGET_MOUNT/dev/pts"
# Set root password from preseed # Set root password from preseed or use default
ROOT_PASS=$(get_preseed_value "passwd/root-password") ROOT_PASS=$(get_preseed_value "passwd/root-password")
if [ -n "$ROOT_PASS" ]; then if [ -n "$ROOT_PASS" ]; then
print_status "Setting root password for installed system..." print_status "Setting root password from preseed file..."
echo "root:$ROOT_PASS" | chroot "$TARGET_MOUNT" chpasswd log "Setting root password from preseed: ${ROOT_PASS:0:10}..."
else
# Ensure password is not expired and account is unlocked # Set default password if none provided
print_status "Ensuring root account is active and password is not expired..." ROOT_PASS="mbetter123"
chroot "$TARGET_MOUNT" passwd -u root 2>/dev/null || true # Unlock account print_status "No root password in preseed file, using default password: mbetter123"
chroot "$TARGET_MOUNT" chage -d 99999 root 2>/dev/null || true # Remove expiration log "Using default root password: mbetter123"
chroot "$TARGET_MOUNT" chage -E -1 root 2>/dev/null || true # Remove account expiration
chroot "$TARGET_MOUNT" chage -m 0 root 2>/dev/null || true # Remove minimum password age
chroot "$TARGET_MOUNT" chage -M 99999 root 2>/dev/null || true # Set maximum password age to never expire
fi fi
# Set the password
echo "root:$ROOT_PASS" | chroot "$TARGET_MOUNT" chpasswd
if [ $? -eq 0 ]; then
print_status "Root password set successfully"
else
print_error "Failed to set root password!"
fi
# Ensure password is not expired and account is unlocked
print_status "Ensuring root account is active and password is not expired..."
chroot "$TARGET_MOUNT" passwd -u root 2>/dev/null || print_warning "Could not unlock root account"
chroot "$TARGET_MOUNT" chage -d 99999 root 2>/dev/null || print_warning "Could not remove password expiration"
chroot "$TARGET_MOUNT" chage -E -1 root 2>/dev/null || print_warning "Could not remove account expiration"
chroot "$TARGET_MOUNT" chage -m 0 root 2>/dev/null || print_warning "Could not set minimum password age"
chroot "$TARGET_MOUNT" chage -M 99999 root 2>/dev/null || print_warning "Could not set maximum password age"
# Create mbetterclient user with no password for autologin # Create mbetterclient user with no password for autologin
print_status "Creating mbetterclient user for autologin..." print_status "Creating mbetterclient user for autologin..."
chroot "$TARGET_MOUNT" useradd -m -s /bin/bash mbetterclient 2>/dev/null || true chroot "$TARGET_MOUNT" useradd -m -s /bin/bash mbetterclient 2>/dev/null || true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment