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?
Best Answer
Ultimately, Debian's (and therefore Ubuntu's)
adduser
callsgpasswd
: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
andgpasswd
, 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.