Skip to main content
Visitor II
October 16, 2023
Question

New user from useradd not found on the /etc/passwd

  • October 16, 2023
  • 1 reply
  • 2644 views

Hi all.

I am adding a new user to my Linux image. After generating the image I verify the `/etc/passwd` on the rootfs and the new user is not present. When I try to login to this new user on the running image itself, it doesn't work. As I am using the "read-only-rootfs" feature, I think some extra setup is required to fix this issue.

 

In order to build my recipe, I followed the instructions from useradd-example.bb .

How to add a new user properly with the read only rootfs feature?

 

PS. I am setting another partition on the /home. So this folder is writable.

 

Thanks

    This topic has been closed for replies.

    1 reply

    Technical Moderator
    November 7, 2023

    Hi @vfranchi ,

    to add a new user, during a yocto training, we were using the following, but I'm far to be an expert:

    # create password hash using openssl
    openssl passwd -5 MY_PASSWORD
    # you get a hash string in a form of $5$nnn...nnn$nnn...nnn
    
    # add hash in my-image (prefix each $ by \)
    gedit ../../layers/meta-my-layer/recipes-core/images/my-image.bb
    	inherit core-image extrausers
    	EXTRA_USERS_PARAMS += "useradd -p '\$5\$nnn...nnn\$nnn...nnn' MY_USERNAME;"

     

    Hope this helps.

    Regards.

    vfranchiAuthor
    Visitor II
    November 7, 2023

    Hi @PatrickF 

    Thank you for your reply.

    I tried the `EXTRA_USERS_PARAMS` before, but it does not work due the read-only-rootfs option. I guess it is because Yocto adds the users after the rootfs recipe is done and then due the immutability it does not work. If I remove the read-only then it works just fine.

    Regarding the `core-image` inherit  from your example, do you know if it causes the users to be added at another moment on the build?

    Thank you.