In addition to the more widespread useradd
, Debian based systems also contain an additional adduser
command which provides a higher level interface for adding users and some related tasks. There are various questions/answers on other SE sites which detail the basic differences between these commands, for example:
- ServerFault – What's the difference between 'useradd' and 'adduser'?
- Superuser – What's the difference between “adduser” and “useradd”?
- Ask Ubuntu – What is the difference between adduser and useradd?
Most of the answers essentially say that adduser
provides nicer interface for adding users interactively, but don't give much detail on what happens when adduser
is run that doesn't compared to useradd
. So:
- What does
adduser
do thatuseradd
doesn't? - What commands do I need to use to produce equivalent results?
Best Answer
First off, the respective man page snippets highlight the differences between the two commands and give some indication of what is going on. For
adduser
:Then for
useradd
:Further investigation of
adduser
reveals that it is a perl script providing a high level interface to, and thus offering some of the functionality of, the following commands:useradd
groupadd
passwd
- used to add/change users passwords.gpasswd
- used to add/change group passwords.usermod
- used to change various user associated parameters.chfn
- used to add/change additional information held on a user.chage
- used to change password expiry information.edquota
- used to change disk usage quotas.A basic run of the
adduser
command is as follows:This simple command will do a number of things:
username
./home/username
and copy the files from/etc/skel
into it.The
useradd
program can most of accomplish most of this, however it does not do so by default and needs additional options. Some of the information requires more commands:Note that
adduser
ensures that created UIDs and GIDs conform with the Debian policy. Creating normal users withuseradd
seems to be ok, providedUID_MIN
/UID_MAX
in/etc/login.defs
matches the Debian policy. What is a problem though is that Debian specifies a particular range for system user UIDs which only seems to be supported in/etc/adduser.conf
, so naively adding a system user withuseradd
and not specifying a UID/GUID in the correct range leaves the potential for serious problems.Another common use for
adduser
is to simplify the process of adding a user to a group. Here, the following command:is equivalent to the following
usermod
command:The main drawback from
usermod
in this case is that forgetting to pass the append option (i.e.:-a
) would end up removing the user from all groups before adding them to "newgroup" (i.e.:-G
alone means "replace with").One downside to using
adduser
here though is that you can only specify one group at a time.