I added a new user as follows
inherit extrausers
EXTRA_USERS_PARAMS = "useradd -P p@ssW0rd user1;"
I am trying to find how to add users to sudoers list. Is there a class like extrausers
Update-1:
In class classes/extrausers.bbclass
I see usermod
supported. Will the following work?
inherit extrausers
EXTRA_USERS_PARAMS = "useradd -P p@ssW0rd user1;\
usermod -aG sudo user1"
Update-2:
I tried adding IMAGE_INSTALL_append += " sudo "
and
inherit extrausers
EXTRA_USERS_PARAMS = "useradd -P foobar -G sudo user1;"
But that does not help me in achieving the effect of adding user1 to sudoers list. I see following error when I do sudo -v
Sorry, user user1 may not run sudo on <machine-name>.
Update-3:
I found that the sudoers file has the sudo group commented as follows:
# %sudo ALL=(ALL) ALL
Hence the reason even adding user1
to group sudo
didn't help
Rather than adding user1
to group sudo
I adopted approach of adding a drop-in file under /etc/sudoers.d/0001_user1
using recipes-extended/sudo/sudo_1.8.14p3.bbappend
do_install_append () {
echo "user1 ALL=(ALL) ALL" > ${D}${sysconfdir}/sudoers.d/001_first
}
Now I need help in understanding which of following is a better approach in terms of security?
sudo
line in /etc/sudoers
and adding user1
to /etc/sudoers
user1
in /etc/sudoers.d/001_first
So there are two approaches to add an user with sudo capability
${D}${sysconfdir}/sudoers.d/
and add the sudo rule for user there.Now which approach is suitable for your distro is well answered in /etc/sudoers vs /etc/sudoers.d/ file for enabling sudo for a user