Yocto Dunfell setting root password in recipe unsuccessful - yocto

I am trying to set the root user password in a custom recipe for yocto Dunfell.
Recipe looks like this: I have also tried EXTRA_USERS_PARAMS_append as shown in some other stackOverflow posts and it also did not work.
SUMMARY = "Test"
LICENSE = "CLOSED"
# Remove debugging tweaks
IMAGE_FEATURES_remove += " \
debug-tweaks \
"
# Add root password, and add the 'test' user
inherit extrausers
EXTRA_USERS_PARAMS = " \
usermod -P testpasswd root; \
useradd -p '' test \
"
FILES_${PN} = " /test/temp \
"
do_install () {
install -d ${D}/test/tmp
}
If I build this with my recipe, I can login as root with no password and when I check /etc/shadow the test user is not created.
I have verified that my desired directory /test/temp is created.

You should also remove allow-empty-password and empty-root-password features from IMAGE_FEATURES if they maybe available. enter link description here
and You didn't use semicolons at end of useradd -p '' test . This can cause error.
And you should be sure that debug-tweaks is not added at other strong files like local.conf

Related

How to add multiple users in Yocto based on machine

I have 5 machines in my Yocto workspace. Is there a way to add users based on machine type?
For example:
Machine 1 has user1, user2
Machine 2 has user1, user2, user3
The useradd-example.bb recipe demonstrates how to write a recipe that creates multiple users, each in their own package.
First, you could follow that example's pattern to create packages for each of the users you need:
# customusers.bb
inherit useradd
PACKAGES =+ "${PN}-user1 ${PN}-user2 ${PN}-user3"
USERADD_PACKAGES = "${PN}-user1 ${PN}-user2 ${PN}-user3"
USERADD_PARAM_${PN}-user1 = "-u 1001 -d /home/user1 -r user1"
USERADD_PARAM_${PN}-user2 = "-u 1002 -d /home/user2 -r user1"
USERADD_PARAM_${PN}-user3 = "-u 1003 -d /home/user3 -r user1"
Then, in each machine.conf file you can add the appropriate packages using MACHINE_ESSENTIAL_EXTRA_RDEPENDS, e.g.:
# machine1.conf
MACHINE_ESSENTIAL_EXTRA_RDEPENDS += "\
customusers-user1 \
customusers-user2 \
"
# machine2.conf
MACHINE_ESSENTIAL_EXTRA_RDEPENDS += "\
customusers-user1 \
customusers-user2 \
customusers-user3 \
"

Yocto Warrior Cannot Set Password for root or other users

I am using the meta-tegra warrior branch layer to build an sd card image for the Nvidia Jetson Nano. The image completes and the board boots, but I cannot log in if I try to set any kind of password in Yocto. I've tried creating users other than root and setting their passwords, but the same problem occurs where I cannot log in.
If I leave "debug-tweaks" enabled, and do not attempt to modify the root password at all, I can successfully log in without a password.
I am using warrior branch for OE and haven't modified other layers. How can I set a password for root?
Here are my local.conf password related lines:
# Password Stuff
INHERIT += "extrausers"
#EXTRA_IMAGE_FEATURES = "debug-tweaks"
EXTRA_USERS_PARAMS = "usermod -P mypassword123 root; "
EXTRA_USERS_PARAMS = " useradd testing; \
useradd mts; \
usermod -p 'testing12345' testing; \
usermod -p 'comp12345' comp; \
usermod with -p (minus p) needs a hash generated from openssl passwd command so you need to set Yocto variable as following:
EXTRA_USERS_PARAMS = "usermod -p $(openssl passwd <some_password>) root;"
If you want to append something to bitbake variable, you need to use _append or += operators, ie:
EXTRA_USERS_PARAMS_append = " useradd testing;"
EXTRA_USERS_PARAMS_append = " useradd mts;"
...

Set new user permissions in Yocto recipe

I have a recipe to add a user called foo:
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM_${PN} = "-P foo -u 1000 -d /home/foo -r -s /bin/bash foo;"
LICENSE = "CLOSED"
do_install () {
install -d ${D}/data/docker
install -d ${D}/home/foo
chown -R foo ${D}/home/foo
chown -R foo ${D}/data/docker
}
FILES_${PN} = " \
/home/foo \
/data \
"
For an obscure reason, data/docker is owned by foo but not /home/foo. Any idea why?
Actually, you don't need to install /home/foo(nor chown) since that task should be already accomplished by useradd, thus you can remove those commands. However, you might want to modify your recipe as follows:
do_install () {
install -d -m 755 ${D}${datadir}/foo
install -d -m 755 ${D}/data/docker
chown -R foo ${D}${datadir}/foo
chown -R foo ${D}/data/docker
}
FILES_${PN} = "${datadir}/foo/* /data/docker/*"
So the reason was that another recipe was creating a subfolder in the home directory first and was owned by root by default.
When the recipe to add the user was baked, the home folder was already created with root permissions.
My solution was to add the creation of this folder in the recipe adding the user instead.
Thanks #danior for the corrections

Yocto: Add custom user to custom group

I have created a custom group e.g "grp1" in my application recipe say "app.bb".
GROUPADD_PARAM_${PN} = "grp1"
I am trying to add my custom user e.g: "user1" to this group "grp1" in "space.bb".
USERADD_PARAM_${PN} = "-d ${localstatedir}/lib/space/ -s /bin/false -G grp1 -U user1"
The useradd command failed: "useradd: group 'grp1' does not exist".
I have also tried adding DEPENDS_${PN} = "app" in space.bb, but it doesn't help.
How can I add my custom user to my custom group in bitbake recipe?
another possible cause of this error, if some recipe is using
inherit extrauser
instead of
inherit useradd
and adding the same group grp1 with the help of
EXTRA_USERS_PARAMS = "\
useradd -p '' grp1; \
groupadd grp1; \
"
instead of classical
GROUPADD_PARAM_libAPP = "grp1"
USERADD_PARAM_libAPP = "--no-create-home --home /var/tmp --shell /bin/nologin --gid grp1 grp1"
will cause a group grp1 duplication and failure of the useradd command

Yocto/Poky sudo not working

In my poky build, I've added a password for root, and also I've added a user "myuser". In addition I've added sudo to the list of IMAGE_INSTALL_append.
When logging as "myuser" and tried to "sudo chmod" a file using the root password, it doesn't work "Sorry try again"...
I can log in normally as root with my password,
Anyone has seen this, is sudo working for poky?
As sudo can be executed an you've got a Sorry try again.. error message I think you either got your password wrong (make sure you use the users password, not roots) or you haven't configured sudo correctly.
For a description on how to use /etc/sudoers take a look at its manpage: https://linux.die.net/man/5/sudoers
No way. There is no su package in Yocto/OE.
Does your image build ? You should have had something like Missing or unbuildable dependency chain error, unless you've created a recipe providing su package.
To add user with sudo capability, below is an example of what you should have in your image's recipe.
Create the user with a suitable password
Add the user to sudo group
Give sudo capabilities to sudo members
I suppose you have an image recipe, or even a bbappend on an existing one.
IMAGE_INSTALL_append = " sudo"
inherit extrausers
PASSWORD = "mypassword"
USER = "myuser"
EXTRA_USERS_PARAMS = "\
useradd -p `openssl passwd ${PASSWORD}` ${USER}; \
usermod -a -G sudo ${USER}; \
"
# Here we give sudo access to sudo members
update_sudoers(){
sed -i 's/# %sudo/%sudo/' ${IMAGE_ROOTFS}/etc/sudoers
}
ROOTFS_POSTPROCESS_COMMAND += "update_sudoers;"
Problem fixed removing "sudo" from IMAGE_INSTALL_append, and just using "su" instead