What is the difference between adduser and useradd?

563,692

Solution 1

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.

also adduser is a wrapper for useradd.

Source: What's the difference between “adduser” and “useradd”?

Solution 2

Always use adduser (and deluser when deleting users) when you're creating new users from the command line. (If you're writing a script, especially if you aim for portability, you might want to use the lowlevel utilities instead – and adduser/deluser might not be available on all distros, e.g. on SuSE.)

The useradd, userdel and usermod commands are lowlevel utilities which are there for historical reasons, while adduser/deluser Do The Right Thing™. (I remember which to use by thinking that user* comes after adduser/deluser in the alphabet, and therefore is "worse".)

According to the respective manpages (on Ubuntu 12.04 Precise Pangolin, i.e. a Debian derivative system).

Manpage for adduser says:

(Emphasis added.)

adduser and addgroup add users and groups to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low level tools like useradd, groupadd and usermod programs, by default choosing Debian policy conformant UID and GID values, creating a home directory with skeletal configuration, running a custom script, and other features. adduser and addgroup can be run in one of five modes:

Manpage for useradd says:

useradd is a low level utility for adding users. On Debian, administrators should usually use adduser(8) instead.

See also: What's the difference between “adduser” and “useradd”? (on SuperUser)

Solution 3

adduser: add user with full profile and info (pass, quota, permission, etc.)

useradd: add user with his name only (if you want to add a temp user with only a name,other info not required)

Solution 4

Another couple of differences, that lead to specific scenarios where useradd might be preferable.

  1. In some newer distros, including Ubuntu 14.4, adduser will prompt for information such as password and "gecos" (data for the finger command). This means it can be less suitable for calling from a script (credit: already mentioned in a comment by Wernight).

    The prompts can be suppressed by passing null arguments:

     adduser --disabled-password --gecos "" USER
    
  2. useradd allows you to pass multiple additional groups to add a user to by means of the -G option. adduser seems to require that you call the command once for each group to add.

Solution 5

adduser is friendlier in that it sets up the account's home folders and other settings (e.g. automatically loading system stats and notifications on login), whereas useradd just creates the user.

Share:
563,692

Related videos on Youtube

Joe Cabezas
Author by

Joe Cabezas

Updated on September 18, 2022

Comments

  • Joe Cabezas
    Joe Cabezas over 1 year

    What is the difference between the commands adduser and useradd on Ubuntu?

    • Admin
      Admin over 10 years
      Same question on Super User and on Server Fault
    • Admin
      Admin over 5 years
      and it is and stays a good, valid question. The issue is not people asking it in respective contexts, it is that this question needs to be asked at all.
  • richsinn
    richsinn almost 10 years
    useradd with the -m option will create the home directory.
  • Ricalsin
    Ricalsin almost 10 years
    +1 and Welcome! I up voted the person who was incapable of explaining their previous down vote. Keep it up! Good programmers always rise to the top - (and don't down vote without an explanation). :)
  • Anders
    Anders over 9 years
    The implimentation isn't that interesting, the semantics are. Like adduser(8) is more userfriendly and creates and set up a user by default the way you expect. And useradd(8) only do what you ask, so do you want a home directory created, you have to tell it to create it for you.
  • MestreLion
    MestreLion over 9 years
    -1: Does not tell the fundamental difference between the commands: they have different roles, one being a low-level tool. The fact that one is a perl script and the other is a binary is irrelevant. Also, there are differences in features.
  • Mads Skjern
    Mads Skjern about 9 years
    I never can remember which one, so this is my stupid mnemonic if it helps anyone :) "user" rhymes with "loser", and "loser" comes last. Thus: adduser, deluser.
  • Wernight
    Wernight about 9 years
    I actually disagree on "Always user adduser": For automated scripts I'd prefer useradd because it's always there, non-interactive, and not distro-specific.
  • Quentin Skousen
    Quentin Skousen over 8 years
    I have to google this every time... How can I help myself remember which is which?
  • pzkpfw
    pzkpfw about 8 years
    @kkhugs to me "adduser" feels the most intuitive because it's a command that sounds like english, while the other does not, semantically. If you remember it as the "most intuitive" of the two, you can also try to remember it as the preferred/easier one.
  • cst1992
    cst1992 almost 8 years
    I tried adduser on openSUSE, and it's not there.(13.2)
  • zrajm
    zrajm almost 8 years
    @cst1992 You're right, I've edited the answer to reflect this. Curiously enough, when I tried locate adduser on a SuSE 11 system at work I found that there was an adduser manpage, but no binary (and neither a deluser manpage nor a command).
  • will
    will almost 8 years
    Apparently there is some difference. I have been ensuring various services that do Not need 'system' privileges have user privilege username-s. Say MySQL or a Wiki - There is no need for a privileged to run these kinds of services. But I tried adduser and lots user-oriented extras were made for my 'service' accounts. So I deleted them and now I just use useradd -- from above: " only do what you ask " (but specified a non-existent home...).
  • answerSeeker
    answerSeeker about 7 years
    useradd is better if you're a true sys admin. Not being able to use adduser in an autonomous script is a real bummer.
  • answerSeeker
    answerSeeker about 7 years
    Doesn't work on ubuntu 16.04.
  • Levon
    Levon almost 7 years
    under Red Hat /usr/sbin/adduser -> useradd .. sheesh ...
  • Levon
    Levon almost 7 years
    On Red Hat /usr/sbin/adduser -> useradd
  • ychaouche
    ychaouche about 6 years
    Wrong. useradd can create home directory with -m, set password with -p, create skeleton files with -k, and add user to group(s) with -G.
  • ychaouche
    ychaouche about 6 years
    Wrong. See previous comment
  • Thörni
    Thörni almost 3 years
    @ychaouche Theres a difference between "will create [...]" and "can create [...]".
  • ychaouche
    ychaouche almost 3 years
    Same difference as using a command with default options and using a command with desired options.
  • Stephen Shank
    Stephen Shank about 2 years
    @pzkpfw Completely agree. What do I want to do? "Add a user". Remove " a " and you've got adduser