9

I am building an image with Yocto/Poky release Daisy 1.6.3.
What is the correct way or config file where to set the root password? The default password is empty and I can't find a place where to specify it.

Alessandro Da Rugna
  • 4,571
  • 20
  • 40
  • 64

6 Answers6

12

Here is what you have to do in your recipe.

inherit extrausers
EXTRA_USERS_PARAMS = "usermod -P p@ssw0rd root;"

where p@ssw0rd is the password you want root user to have.

This link may help you.

As "debug-tweaks"'s goal is to set root's password empty, you must remove it from your EXTRA_IMAGE_FEATURES.

john madieu
  • 1,209
  • 12
  • 16
  • 1
    I realize this is a few years old, but it's important to point out that this class and variable are intended at the _image level_ recipe, not a package, etc. ([rocko](https://www.yoctoproject.org/docs/2.4.3/ref-manual/ref-manual.html#ref-classes-extrausers)) – Thomas Aug 10 '18 at 18:26
5

As of Poky 2.1.2; to set the root password the following instructions need to be added to local.conf:

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = "usermod -P p@ssw0rd root;"

No need to remove debug-tweaks

john madieu
  • 1,209
  • 12
  • 16
4

In your image recipe:

  1. Set a plain password:
inherit extrausers  
EXTRA_USERS_PARAMS = "usermod -P MyPass root;"
  1. Or set a hashed password (notice that insert \ before dollar signs):
inherit extrausers  
EXTRA_USERS_PARAMS = "usermod -p '\$6\$3trMG9KVzGF3942L\$pHeO/r4/RIEFU1tZzoPXYlJLHNvmeJFZdIwQCcTrZFq5kpIgTxoEOJBO5iYEvLzeMjhZRtXhTPbOD4RFAelwk0' root;"

Note: for hashing your plain password, use can use openssl:

$ openssl passwd -6
Password:
Verifying - Password:
$6$3trMG9KVzGF3942L$pHeO/r4/RIEFU1tZzoPXYlJLHNvmeJFZdIwQCcTrZFq5kpIgTxoEOJBO5iYEvLzeMjhZRtXhTPbOD4RFAelwk0
Musa
  • 474
  • 4
  • 9
3

As of Poky 4.0.7, none of the answers here work because the -P clear text password flag is no longer supported as per this commit. You will get an error message like usermod: prefix must be an absolute path. Now, only the -p encrypted password flag is supported. To set your root password to password add below to your conf/local.conf file:

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = "usermod -p '\$1\$EZkCDWad\$eEMhB36cFCOeRGXvtP3t81' root;"

you can generate your own password string with openssl passwd -1 but note that $ needs to be escaped with \ as shown in the example.

Alex
  • 3,441
  • 4
  • 18
  • 30
  • I'm using SHA512 to hash the password but not working. my question is here https://unix.stackexchange.com/questions/754866/yocto-linux-root-logging-error-libcrypt-does-not-support-md5-or-sha512 any help – bouqbouq Aug 25 '23 at 12:47
2

Here is method I used which does not use the -P switch on the usermod command. You must use the following form:

EXTRA_USERS_PARAMS = "usermod -p $(openssl passwd p@ssw0rd) root;"

The usermod -P command does not work in my version of linux.

See How do i change the root password in the Yocto dora bitbake system?

P Moran
  • 1,624
  • 3
  • 18
  • 32
1

Add the below linw at your conf/local.conf file

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = "usermod -P urpassword root;"
yoctotutor.com
  • 5,145
  • 4
  • 26
  • 36