Search code examples
passwordssudoyoctorecipe

How to add Sudouser in Yocto


I'd like to add a new Sudouser in Yocto. Root password works well with changes and new user is added, but it is not Sudouser. How can I add Sudouser? I read a lot of Google articles and tried to copy them, but they all failed. I made a recipe but it didn't work and only added it to the local.conf is working.

  1. Add extrausers. (new user : test1, password : pass11!)
  2. Desable debug-tweaks to change the password of root.
  3. Change root password. (None --> pass1234!)

The following is my code which added in local.conf.

# EXTRA_IMAGE_FEATURES = "debug-tweaks package-management"

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = " usermod -P pass1234! root; \
                       useradd test1; \
                       usermod -P pass11! test1; "

I would be grateful for any suggestions.


Solution

  • Thank you Robert. I found the solution from Toradex engineer.

    If someone has a problem like me, try the following.

    1. Change root password.

    Add the following in local.conf. I didn't use my recipe.

    EXTRA_IMAGE_FEATURES=""
    INHERIT += "extrausers"
    EXTRA_USERS_PARAMS = " usermod -P password root; "
    

    If someone can't use ssh, please refer to here

    1. Add new user who has root permission.
    EXTRA_IMAGE_FEATURES=""
    INHERIT += "extrausers"
    EXTRA_USERS_PARAMS = " usermod -P password1 root; \
                useradd -ou 0 -g 0 newuser; \ 
                usermod -P password2 newuser; "
    

    Maybe your user account can't use some command like "ifconfig" because your user account doesn't have the path "/sbin". Go to your Yocto code and find the correct file and add /sbin for your user accout.

    r@p:~/oe-core/layers$ grep -r /etc/profile .
    ./meta-toradex-demos/recipes-core/base-files/base-files/profile:# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
    ./meta-toradex-demos/recipes-core/base-files/base-files/profile:if [ -d /etc/profile.d ]; then
    ./meta-toradex-demos/recipes-core/base-files/base-files/profile:  for i in /etc/profile.d/* ; do
    
    if [ "$HOME" = "/home/root" ]; then
       PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
    fi
    
    if [ "$HOME" = "/home/newuser" ]; then
       PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
    fi