3

in Linux I can do this to create a new user and allow it to call sudo:

useradd -m -s /bin/bash -g group1 user1
usermod -a -G sudo,www-data user1


# /etc/sudoers
%sudo   ALL=(ALL:ALL) NOPASSWD: ALL

How can I do the same in FreeBsd?

useradd
useradd: Command not found.

Note that I don't want an interactive way to create a user -- adduser -- because I want to be able to run it from a bash script without having to type any details in the terminal.

update:

It's FreeBsd 11.

3

FreeBSD, TrueOS, and relatives

  • pw useradd user1 -g group1 -s /usr/local/bin/bash
  • pw usermod user1 -G wheel,www-data

Or simply

  • pw useradd user1 -g group1 -s /usr/local/bin/bash -G wheel,www-data

Note that the FreeBSD port of sudo normally configures wheel not sudo. Also note that you'll have to install the Bourne Again shell from ports/packages. Finally note that pw usermod has no notion of appending to the secondary group list. One has to set the entire list.

Further reading

  • pw. FreeBSD 11.0 Manual.

OpenBSD

  • useradd -g group1 -s /usr/local/bin/bash user1
  • usermod -G wheel,www-data user1

Or simply

  • useradd -g group1 -s /usr/local/bin/bash -G wheel,www-data user1

Note that you'll have to install sudo from ports/packages. The OpenBSD tool that comes in the operating system is doas nowadays. Also note that you'll have to install the Bourne Again shell from ports/packages. Finally note that OpenBSD's -G option to usermod always implies appending. To set the entire secondary group list, one uses -S.

Further reading

  • is it applicable for FreeBsd 11 also? Or is there a better way to do that in FreeBsd 11? – Kooooro Dec 1 '16 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.