How to do it...

The standard way for a recipe to add or modify system users or groups is to use the useradd class, which uses the following variables:

  • USERADD_PACKAGES: This variable specifies the individual packages in the recipe that require users or groups to be added. For the main package, you would use the following:
USERADD_PACKAGES = "${PN}" 
  • USERADD_PARAM: This variable corresponds to the arguments passed to the Linux useradd command, to add new users to the system.
  • GROUPADD_PARAM: This variable corresponds to the arguments passed to the Linux groupadd command, to add new groups to the system.
  • GROUPMEMS_PARAM: This variable corresponds to the arguments passed to the Linux groupmems command, which administers members of the user's primary group.

The useradd class will add shadow passwords to the system as a dependency.

An example snippet of a recipe using the useradd class follows:

inherit useradd 
 
PASSWORD ?= "9PfNy0O1z0O5g" 
USERADD_PACKAGES = "${PN}" 
USERADD_PARAM_${PN} = "--system --create-home   
                       --groups tty   
                       --password ${PASSWORD}   
                       --user-group <newuser>" 

The password can be generated on your host using the mkpasswd Linux command-line utility, installed with the whois Ubuntu package:

$ mkpasswd password
9VuPL5UF0N7lg  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset