Fix password setting by using passwd --stdin and sync

This commit is contained in:
2026-02-05 17:25:00 +01:00
parent 7613bdf8d5
commit ee83411333

View File

@@ -236,12 +236,15 @@ UUID={efi_uuid} /boot vfat defaults 0 2
# Create user and add to wheel group (sudoer) # Create user and add to wheel group (sudoer)
run_command(["chroot", mount_root, "useradd", "-m", "-G", "wheel", user_info["username"]]) run_command(["chroot", mount_root, "useradd", "-m", "-G", "wheel", user_info["username"]])
# Set password # Ensure changes to /etc/passwd and /etc/shadow are flushed
run_command(["sync"])
# Set password using passwd --stdin
try: try:
logger.info("Setting user password...") logger.info("Setting user password...")
p = subprocess.run( p = subprocess.run(
["chroot", mount_root, "chpasswd"], ["chroot", mount_root, "passwd", "--stdin", user_info["username"]],
input=f"{user_info['username']}:{user_info['password']}\n", input=f"{user_info['password']}\n",
text=True, text=True,
check=True, check=True,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,