0

I need to set the root password in the autoinstall as it allows me to check the system by logging into the console after installation. Unfortunately, this doesn't seem to work, and I have the following:

#cloud-config
users:
  - name: root
    lock_passwd: false
    hashed_passwd: <output from mkpasswd --method=SHA-512>

I even tried using late-commands run-command sections with chpasswd commands like the following, but it didn't work

chroot /target sh -c 'echo "root:<output from mkpasswd --method=SHA-512>" | /usr/sbin/chpasswd -e'

Is it possible to change the root password using auto-install? If so, I would appreciate any assistance. Thanks

Prasad
  • 1

1 Answers1

0

The user-data section can be used. With this option cloud-init will set the root password during first boot. Be aware that the root password hash will be in /etc/cloud/cloud.cfg.d/99-installer.cfg on the installed system.

#cloud-config
autoinstall:
  user-data:
    chpasswd:
      expire: false
      list:
        - root:$6$REDACTED

Alternatively you can use late-commands. This will set the password during the install. Be aware the root password hash will be in the installer logs in /var/log/installer on the installed system.

#cloud-config
autoinstall:
  late-commands:
    - |
      echo 'root:$6$REDACTED' | /usr/sbin/chroot /target chpasswd -e

The chroot needs to be after the pipe so the proper command is chrooted.

note

You can not use the cloud-init users module to set the password for root because the root user exists. The config schema documentation explicitly states

passwd: ... This will NOT be applied if the user already exists

see also