4

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?

  • uncomment sudo line in /etc/sudoers and adding user1 to /etc/sudoers
  • adding user1 in /etc/sudoers.d/001_first
sob
  • 982
  • 11
  • 31
  • 1
    you could try to add the user to group "wheel" by default, which should be in sudoers already. like: useradd -P somepass -G wheel user1; – Tuncay Göncüoğlu Jul 04 '17 at 17:10
  • People mention it works there https://stackoverflow.com/questions/44043874/how-to-add-an-user-and-re-set-the-root-user-in-yocto . – David Bensoussan Jul 05 '17 at 05:45
  • @TuncayGöncüoğlu, When I try adding to wheel. I see wheel does not exist. `useradd: group 'wheel' does not exist` – sob Jul 05 '17 at 08:16

1 Answers1

1

So there are two approaches to add an user with sudo capability

  • Add user to sudo group and enable sudo group in /etc/sudoers
  • Create a file under ${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

sob
  • 982
  • 11
  • 31