Use live system root password for installed system

- Copy live system's root password hash directly to installed system
- Eliminates need to remember separate passwords for live vs installed
- Uses sed to replace root line in target /etc/shadow with live system hash
- Falls back to default 'mbetter123' if live password copy fails
- Maintains SSH compatibility and password authentication
parent 03aa4048
......@@ -540,24 +540,46 @@ configure_target_system() {
mount -o bind /dev "$TARGET_MOUNT/dev"
mount -t devpts devpts "$TARGET_MOUNT/dev/pts"
# Set root password from preseed or use default
# Set root password from preseed, live system, or use default
ROOT_PASS=$(get_preseed_value "passwd/root-password")
if [ -n "$ROOT_PASS" ]; then
print_status "Setting root password from preseed file..."
log "Setting root password from preseed: ${ROOT_PASS:0:10}..."
# Set the password using chpasswd
echo "root:$ROOT_PASS" | chroot "$TARGET_MOUNT" chpasswd
else
# Set default password if none provided
ROOT_PASS="mbetter123"
print_status "No root password in preseed file, using default password: mbetter123"
log "Using default root password: mbetter123"
# Try to copy password from live system
LIVE_ROOT_HASH=$(grep '^root:' /etc/shadow | cut -d: -f2)
if [ -n "$LIVE_ROOT_HASH" ] && [ "$LIVE_ROOT_HASH" != "*" ] && [ "$LIVE_ROOT_HASH" != "!" ] && [ "$LIVE_ROOT_HASH" != "x" ]; then
# Copy the live system's root password hash directly to target shadow file
print_status "Copying live system root password to installed system..."
log "Copying live system root password hash to installed system"
# Get the full root line from live shadow
LIVE_ROOT_LINE=$(grep '^root:' /etc/shadow)
# Replace the root line in target shadow file
sed -i "s|^root:.*|${LIVE_ROOT_LINE}|" "$TARGET_MOUNT/etc/shadow"
if [ $? -eq 0 ]; then
print_status "Live system root password copied successfully"
log "Live system root password hash copied to target system"
else
print_warning "Failed to copy live password, using default"
echo "root:mbetter123" | chroot "$TARGET_MOUNT" chpasswd
fi
else
# Set default password if none available
print_status "No root password available, using default password: mbetter123"
log "Using default root password: mbetter123"
echo "root:mbetter123" | chroot "$TARGET_MOUNT" chpasswd
fi
fi
# Set the password
echo "root:$ROOT_PASS" | chroot "$TARGET_MOUNT" chpasswd
if [ $? -eq 0 ]; then
print_status "Root password set successfully"
# Verify password was set
if chroot "$TARGET_MOUNT" passwd -S root | grep -q "Password set"; then
print_status "Root password verification successful"
else
print_error "Failed to set root password!"
print_warning "Root password verification failed"
fi
# Ensure password is not expired and account is unlocked
......
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