FAQ:How do I set or change the root password: Difference between revisions

From Yocto Project
Jump to navigationJump to search
No edit summary
(Include note and example for escaping the $ characters to preserve pwd hash in generated files.)
Line 4: Line 4:


  inherit extrausers
  inherit extrausers
  EXTRA_USERS_PARAMS = "usermod -p '$5$sIhB3FmJb4oSx.uN$WWE8AJP8ybR03TXBJ2JMZJ6LpsrvcwKmsHxxY.asDR6' root;"
  EXTRA_USERS_PARAMS = "usermod -p '\$5\$sIhB3FmJb4oSx.uN\$WWE8AJP8ybR03TXBJ2JMZJ6LpsrvcwKmsHxxY.asDR6' root;"


This sets the root password to a hashed value of "1876*18". If you prefer to do this in local.conf or your distro configuration, you'll need to change the first line to <code>INHERIT += "extrausers"</code>.
This sets the root password to a hashed value of "1876*18". If you prefer to do this in local.conf or your distro configuration, you'll need to change the first line to <code>INHERIT += "extrausers"</code>.
Line 16: Line 16:
|}
|}


Note some characters may need some level of escaping to make it correctly into <code>/etc/shadow</code> (examples shown should work)


'''Q:''' How do I add users?
'''Q:''' How do I add users?
Line 22: Line 23:


  inherit extrausers
  inherit extrausers
  EXTRA_USERS_PARAMS = "useradd -p '$5$vn9du4U3jghFZaqC$Fl6pQZK5FUoT2D6Twij3OpjGR9FXFsE1r/vyMtGooX6' myUser;"
  EXTRA_USERS_PARAMS = "useradd -p '\$5\$vn9du4U3jghFZaqC\$Fl6pQZK5FUoT2D6Twij3OpjGR9FXFsE1r/vyMtGooX6' myUser;"


This adds the user myUser and sets the password to a hashed value of "2015*08". As above, if you prefer to do this in local.conf or your distro configuration, you'll need to change the first line to <code>INHERIT += "extrausers"</code>.
This adds the user myUser and sets the password to a hashed value of "2015*08". As above, if you prefer to do this in local.conf or your distro configuration, you'll need to change the first line to <code>INHERIT += "extrausers"</code>.

Revision as of 17:08, 18 February 2022

Q: How do I set / change the root password?

A: Use the extrausers class to set the password. In your image recipe:

inherit extrausers
EXTRA_USERS_PARAMS = "usermod -p '\$5\$sIhB3FmJb4oSx.uN\$WWE8AJP8ybR03TXBJ2JMZJ6LpsrvcwKmsHxxY.asDR6' root;"

This sets the root password to a hashed value of "1876*18". If you prefer to do this in local.conf or your distro configuration, you'll need to change the first line to INHERIT += "extrausers".

To obtain the hashed value for a password, you can use the following command:

$ python -c 'import crypt; print(crypt.crypt("1876*18", crypt.METHOD_SHA256))'
WARNING: if you are hardcoding a root password for a production image deployed to multiple devices, consider carefully the ramifications of doing so before proceeding.

Note some characters may need some level of escaping to make it correctly into /etc/shadow (examples shown should work)

Q: How do I add users?

A: Use the extrausers class to and the user and set the password. In your image recipe:

inherit extrausers
EXTRA_USERS_PARAMS = "useradd -p '\$5\$vn9du4U3jghFZaqC\$Fl6pQZK5FUoT2D6Twij3OpjGR9FXFsE1r/vyMtGooX6' myUser;"

This adds the user myUser and sets the password to a hashed value of "2015*08". As above, if you prefer to do this in local.conf or your distro configuration, you'll need to change the first line to INHERIT += "extrausers".