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


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?


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.

  • 1
    This also gave me the idea to open commands in an editor and check the Perl script to see how it works. – RationalDev likes GoFundMonica Apr 26 '15 at 7:33
  • so... you recommend gpasswd? I wonder why debian recommends adduser – Mr-Programs Jan 28 '19 at 15: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.