9

To add a new sudo user I believe I can call:

# to create a new user
sudo adduser newusername

and to allow this user to use sudo I can do:

sudo adduser newusername sudo

or

sudo gpasswd -a newusername sudo

If this is correct, is there any difference between these commands or reasons to use one over the other for primarily Ubuntu server hardening script, but also trying to be as generic as possible, eg different Linux versions or distribution compatibility?

1 Answer 1

6

Ultimately, Debian's (and therefore Ubuntu's) adduser calls gpasswd:

my $gpasswd = &which('gpasswd');                           
&systemcall($gpasswd, '-a',$existing_user,$existing_group);

Debian's adduser was written with the purpose of being a convenient frontend to a range of utilities (it makes use of, at one step or another, useradd, gpasswd, usermod, passwd, chfn, and a couple more commands). adduser and co. are somewhat distro-specific in nature, being frontend scripts. The one you see is from Debian, while Slackware and FreeBSD (at least) have their own.

I'd expect a consistent interface with the lower level commands like usermod and gpasswd, since they seem to originate from a common set of tools according to the origins of the package in Debian (and thereby Ubuntu, Arch Linux, Fedora, and CentOS), and Slackware.

On the other hand, Debian recommends that system administrators use adduser, etc.

2
  • 1
    This also gave me the idea to open commands in an editor and check the Perl script to see how it works. Commented Apr 26, 2015 at 7:33
  • 1
    so... you recommend gpasswd? I wonder why debian recommends adduser Commented Jan 28, 2019 at 15:02

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.