Adduser and addgroup: interactive tools for creating a user account and a user group
What is a user account?
adduser is a tool in console mode allowing to create a user account in an interactive way. It is a Perl script specific to Debian and its derived distributions – such as Ubuntu – that asks questions about an account to create, then invokes the usermod program and passes the information it retrieves as arguments. This tool is therefore very easy and intuitive to use. addgroup is its counterpart in terms of creating a user group.
Only a system administrator can create a new user account or group.
Ubuntu, like all other operating systems in the GNU/Linux family, is inherently multi-user. This means that you are not limited to a single user account in the operation of your computer. You can create multiple user accounts for each user of your computer, as well as for various uses.
The adduser command, invoked by an administration account, starts the user account creation script :
sudo adduser username
The information to be assigned to the new user account is then requested one by one. Pressing the [Enter] key on the keypad registers the information entered and proceeds to the next question.
When all the required information has been retrieved, a summary is presented to the administrator. The administrator must then confirm the creation of the new account or repeat the operation. Upon confirmation of the information, the script calls useradd to create the new account and creates a new personal folder from the structure contained in the /etc/skel/ directory.
Some options can be specified to adduser, to provide some additional parameters. See the adduser manual to read more about these options.
[email protected]:~$ sudo adduser jdoe
[sudo] password for administrator:Adding user `jdoe' ... Adding new group `jdoe' (1001) ... Adding new user `jdoe' (1001) with group `jdoe' ... Creating home directory `/home/jdoe' ... Copying files from `/etc/skel' ...
Enter the new UNIX password: (new password)
Retype the new UNIX password: (password repeated)
Changing the user information for jdoe
Enter the new value, or press ENTER for the defaultFull Name : John Doe Room Number : 333, Av. Blalak Work Phone : (555) 123-4567 Home Phone : (555) 987-6543 Other : [email protected] Is the information correct? [Y/n] y [email protected]:~$ _
To force the user to change the password the first time he logs in, you can use the passwd command.
[email protected]:~$ sudo passwd -e jdoe
passwd: password expiration modified.
The addgroup command, invoked by an administrative account, starts the user group creation script :
sudo addgroup groupName
To assign a user account to this new group, use adduser as follows:
sudo adduser userName groupName
where identifier is an existing user account identifier. The account must already exist; the command does not work with an account that does not exist.
3. Create an account or a user group in a non-interactive way
Adduser and addgroup are interactive tools, i.e. they ask a series of questions that must be answered by the administrator in order for the account or user group to be created. This is interesting to create a single account or group, but becomes a handicap to create several at the same time. adduser and addgroup are not scriptable. To use a non-interactive tool, ask about :
useradd for user accounts
groupadd for user groups
4. Impacted files
The above commands modify the following system files, which are obviously not recommended to modify manually:
/etc/passwd /etc/shadow /etc/group
The /etc/passwd file contains the following information about user accounts :
username is the user’s login.
password corresponds to the user’s password replaced by an x for security reasons.
uuid is the user’s system ID.
guid is the user’s main group.
comment (sometimes called GECOS field) is a textual comment about the user, which is often his real name (first and last name) and other information (office number, phone…) separated by commas.
home corresponds to the home directory of the user on this system, /dev/null if account without home (on a server).
shell is the user’s default shell interpreter, /bin/false to prevent shell use (on a server).