93

I wonder: Why are there these two commands on Debian Linux, with very similar names and functionality? This has always been confusing for me.

  • Is any of them superior to another?
  • Why aren't they merged into one?
  • Is there any significant difference between them?
  • Which one should I use? Or does it depend on a use case?
2
  • 4
    Note that useradd is available on all Unix-like platform; adduser is only for Debian and its derivatives. Apr 3, 2019 at 19:21
  • Alpine Linux uses BusyBox which only has adduser. useradd is only available if the shadow package is installed.
    – Martin
    Jul 11, 2022 at 11:18

5 Answers 5

101

useradd is native binary compiled with the system. But, adduser is a perl script which uses useradd binary in back-end.

adduser is more user friendly and interactive than its back-end useradd. There's no difference in features provided.

3
  • 4
    adduser isn't available on all distros (eg. suse-based), and on some others it's just a symlink to useradd (redhat-based).
    – ychaouche
    Feb 21, 2018 at 12:30
  • 1
    adduser provides an option --disabled-password while useradd doesn't. But I guess that useradd can do the same using a different option or combination of options (like --inactive or something like that). Mar 10, 2020 at 20:57
  • @DavidFerenczyRogožan "adduser provides an option --disabled-password while useradd doesn't". There is no need; the password is already disabled by default. From <manpages.debian.org/jessie/passwd/useradd.8.en.html>: "-p, --password PASSWORD The encrypted password, as returned by crypt(3). The default is to disable the password.". The more usual way to set the password (outside of Debian at least) is to use passwd (i.e.: after useradd).
    – kelvin
    Nov 12, 2020 at 1:20
17

The main advantage to adduser over useradd is dealing with system level users. With adduser the system level users account when created puts a user directory in home for the system user where useradd does not automatically. If you read the man they are essentially the same except for system level users and associated home directories are automatic. adduser creates a /home/user directory automatically for system level users where there is not a provision in useradd, except if specified by -m option. The other readings I have come across generically state that UID and GUID are assigned by accepted conformal Debian standards in adduser.

1
  • 2
    adduser has a --no-create-home option.
    – ychaouche
    Feb 21, 2018 at 12:31
5

In a couple of Redhat instances I checked (4.9 from 2011 and 6.9 from 2017), adduser is simply an alias to useradd, not a Perl script. Here it is in Redhat 6.9:

$ ls -la /usr/sbin/useradd /usr/sbin/adduser
lrwxrwxrwx. 1 root root      7 Nov  2  2016 /usr/sbin/adduser -> useradd
-rwxr-x---. 1 root root 111320 Feb  9  2016 /usr/sbin/useradd

The way I remember that useradd is the 'correct' program is this: adding a user is just one operation in the CRUD spectrum. You also need 'modify' and 'delete' operations ('read' is presumably covered by viewing /etc/passwd). And so, the programs are named user* (useradd, usermod and userdel respectively). I suppose the alternative *user naming convention (adduser, moduser and deluser -- these don't exist) could also work. But it would be slightly more awkward (for a reason I cannot express clearly at the moment :)

1
  • can't find moduser on Debian, but deluser is definitely there.
    – ychaouche
    Feb 21, 2018 at 12:34
1

One significant difference I ran into (and did not see in an answer here), is that useradd --system seems to imply --shell /bin/bash, while adduser --system implies --shell /usr/sbin/nologin, which is what I wanted.

But I also wanted no home directory (which is the default with useradd but not with adduser), so I could either use useradd like this

useradd --system --shell /usr/sbin/nologin foo

(or /bin/false is also popular for no shell)

Which leads to e.g. the following entry in /etc/passwd

foo:x:994:991::/home/foo:/usr/sbin/nologin

Or use adduser like this

adduser --system --no-create-home foo

Which leads to e.g. the following entry in /etc/passwd

foo:x:110:65534::/home/foo:/usr/sbin/nologin

Note that there are also very different automatic assignment of (G)UIDs. useradd seems to pick them counting downwards from 999, while adduser counts updwards from 100 for the UID and uses 65534 for the GUID (which seems to mean no group). In fact, useradd also creates a group (see /etc/group), while adduser doesn't.

So for me, I will stick with adduser having learnt all those facts.

Source: Tested on Raspberry Pi OS (Debian Buster based).

0

Within raspian (I would need to check for other OSs), 'adduser USER' starts a dialog (TUI) while 'useradd USER' does NOT.

Apparently, using adduser, once the dialog comes up, the full 'useradd' command is already executed. Even if you CTRL-C your user is there.

As in the new systems they create "personal" groups, to remove the newly created user you would need to:

  • vi /etc/passwd
  • vi /etc/group
  • rm -rf /home/USER

I assume that because adduser "uses" useradd, the rest is metadata about the user. So technically no changes in "skel", "file masks", or the like, i.e. your system defaults.

On the other side, because useradd does not bring up any TUI, it might be more useful in scripting.

To be honest I tested it only in rasbian, because that was the reason I stepped on the question.

I can imagine that other OSs might implement a different version of adduser.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .