3

What's the difference between these two commands?

sudo adduser Alex 

and

sudo adduser -m -c "Alex Hales" -s /bin/bash Alex

The first command is simple and creates the user without any directory mentioned, while the second command is an elaborate one with a specific directory.

Can anyone explain the use of second commands and its -m, -c and -s options?

2 Answers 2

7

It seems you're confusing the two commands adduser and useradd (and yes, it's understandable that this can be confusing). Quoting from the respective manpages (linked above):

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

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.

* Also Ubuntu

The options you are referring to are for the useradd command (the low-level utility - from the manpage):

-c, --comment COMMENT
    Any text string. It is generally a short description of the login, and is currently
    used as the field for the user's full name.

-m, --create-home
    Create the user's home directory if it does not exist. The files and directories
    contained in the skeleton directory (which can be defined with the -k option) will be
    copied to the home directory.

    By default, if this option is not specified and CREATE_HOME is not enabled, no home
    directories are created.

-s, --shell SHELL
    The name of the user's login shell. The default is to leave this field blank, which
    causes the system to select the default login shell specified by the SHELL variable in
    /etc/default/useradd, or an empty string by default.

However, by using adduser instead, a home directory will be created, and the default shell will be used. For normal operation, it is recommended to use adduser for an easier experience.

4

EDIT: As Artur Meinild explained, the options you're asking about are for the command useradd, not for the command adduser. This can be confusing, even linux.die.net shows the man page for useradd on the page for adduser. The following is about useradd. If you're looking for the options that adduser understands, you can find them on the man page for adduser.


A very valuable tool for using any Linux system are the man pages, short for "manual pages". You can typically reach them on the command line with man name_of_the_command, for example man ls or man useradd. Not every command comes with a man pages, but very many do, especially the more common and basic ones. Additionally, you can find many man pages online, for example the man pages for useradd.

There are other forms of documentation, as well, for example when you get into programming and are using a third-party library. It is generally a good idea to read up on any command you find anywhere and look into what it's actually doing. If you're just go copy and paste, almost like a magic incantation, you'll probably run into bad suprises rather quickly.

In this specific case, the man page for useradd says about the additional options used in

sudo useradd -m -c "Alex Hales" -s /bin/bash Alex

the following:

-m, --create-home
    Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory.

    useradd will create the home directory unless CREATE_HOME in /etc/login.defs is set to no.

and

-c, --comment COMMENT
    Any text string. It is generally a short description of the login, and is currently used as the field for the user's full name.

and

-s, --shell SHELL
    The name of the user's login shell. The default is to leave this field blank, which causes the system to select the default login shell specified by the SHELL variable in /etc/default/useradd, or an empty string by default. 
1
  • 2
    @HenningKockerbeck that's another reason for not using linux.die.net. I never use it as a reference because it's not clear which distro's manages are being presented (in some cases the manages I got were clearly from the Red Hat family, in some others the Debian family). Always best to use the disto's manpage site when you can, like manpages.ubuntu.com, manpages.debian.org, man.archlinux.org, etc.
    – muru
    Commented Jul 8 at 8:47

You must log in to answer this question.

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