Search code examples
linuxembedded-linuxyocto

Set root password in yocto kirkstone


I tried to set my a password for the root by several approches. Nothing worked for me so far. I added to the local.conf:

INHERIT += "extrausers"
EXTRA_USER_PARAMS = "usermod -P 'mypasswd' root;"

I also tried encrypting the password using "openssl passwd -6 -salt 12345 mypasswd":

INHERIT += "extrausers"
EXTRA_USER_PARAMS = "usermod -p '\$6\$12345\$CdkMCUqHIe6eWfFhMIppyUE/S.iLGe.PACPivJhw05ideCyogNpnVNDIBSQXhSruJxfZCasTi6YvFOrPgFvM7/' root;"

I tried both variants with and without EXTRA_IMAGE_FEATURES ?= "debug-tweaks". I also tried to set the password in sources/meta-qoriq/recipes-kernel/linux/linux-qoriq.inc which gets included in the kernel recipe "sources/meta-qoriq/recipes-kernel/linux/linux-qoriq_5.15.bb" like this "require linux-qoriq.inc". With EXTRA_IMAGE_FEATURES ?= "debug-tweaks" set, no password was set and without it the password was wrong. I also tried to edit the /ect/shadow file manually using the ROOTFS_POSTPROCESS_COMMAND. Therefore I added this lines in the sources/meta-qoriq/recipes-kernel/linux/linux-qoriq.inc file as it seems not to be possible to add a bash function to the local.conf file.

set_pw () {
    encrypted=$(openssl passwd -6 -salt 12345  mypasswd)
    sed -i "s/^root::/root:$encrypted:/" ${IMAGE_ROOTFS}/etc/shadow
}
ROOTFS_POSTPROCESS_COMMAND += "set_pw;"

This also did not work. My board is a freescale LS1046ARDB. That's why im using the linux qoriq distribution from freescale.

EDIT:

Adding:

inherit fsl-utils
ROOTFS_POSTPROCESS_COMMAND += "set_pw;

to the .bb file of the image I'm building (sources/meta-qoriq/recipes-fsl/images/fsl-image-networking.bb) and adding the set_pw function to the sources/meta-qoriq/classes/fsl-utils.bbclass file worked for me. It was not possible to add the bash function to the fsl-image-networking.bb file directly. But I'm still wondering why the

INHERIT += "extrausers"
EXTRA_USER_PARAMS = "usermod -P 'mypasswd' root;"

is not working. That's how it worked in some other posts like this one How to set root password on Yocto / Poky image?. Has the syntax of doing this changed in kirkstone?


Solution

  • Probably a typo on the variable name? The correct is EXTRA_USERS_PARAMS (note the plural of users), see the official documentation.

    BTW, the best practices are discussed here: How to securely update configuration for root password in yocto?