Linux adduser/addgroup Command Tutorial for Beginners (7 Examples)

As a Linux system administrator, one of the basic tasks that you'll have to perform is to create accounts for new users and manage user groups. Of course, there are command line utilities that let you do this, and this tutorial, we will discuss the basics of two such commands: adduser and addgroup.

Before we move ahead, it's worth mentioning that all examples in this article have been tested on Ubuntu 16.04 LTS. Also, the article mainly discusses adduser, but addgroup also works in the same way for the most part.

Linux adduser/addgroup commands

As the name suggests, these tools let you add new users and groups to the system. Here's the basic syntax of these commands:

adduser [options or flags] user
addgroup [options or flags] group

Following is how the man page describes these tools:

       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  fea?

The following Q&A-styled examples should give you a good idea on how these utilities work.

Q1. How to use adduser and addgroup commands?

Adding a user or group is fairly easy - all you have to do is to pass the name of the new user (or group) to the command. For example:

adduser [user-name]

Needless to say, you need to be root, or require escalated privileges for this process to work. The following screenshot shows a new user being added through this tool:

How to use adduser and addgroup commands

So you can see, you'll be asked a few questions, that you can choose to answer to press ENTER so that the system picks default values by itself.

Add a Linux user with adduser command

Once added, you can switch to the new user using the su command in the following way:

Su command

Q2. How to make adduser/addgroup use different conf file?

As already mentioned in the beginning, by default, the adduser/addgroup commands read the /etc/adduser.conf file to carry out their operations. However, if for some reason, you want them to read a custom file residing at a custom location, you can pass that information using the --conf option.

adduser --conf [new-conf-file-name-path]

Q3. What's the difference between system and normal user/group?

If you take a look at the man page documentation of these utilities, you will find that you can use adduser to add either a normal user or a system user.

Add a normal user
       If  called  with  one  non-option  argument and without the --system or
       --group options, adduser will add a normal user.
Add a system user
       If called with one non-option argument and the --system option, adduser
       will add a system user.

It's important that you first know the difference between two.

While technically there isn't a difference between these users, you should create a system user when creating an account to run a system software like a daemon or a service - basically, if the account doesn't require interactive usage. All in all, this segregation helps keep user and software accounts separate.

Q4. How to prevent a user from logging in?

If you want to disable a user account, meaning preventing a user from logging in, use the --disabled-login option.

adduser --disabled-login [OPTIONS] user

This option sets the password to !, which means "login is deactivated, user will be unable to login."

Keep in mind that this will only prevent user login - you can still switch to this account from some other using the su command.

Q5. How to force adduser to create a custom home directory?

As already discussed, the adduser command picks information from a configuration file, and this information includes directory to be used as user's home directory. However, if you want, you can specify this yourself using the --home option.

adduser --home [dire-name-path] user
--home DIR
              Use  DIR  as  the user's home directory, rather than the default
              specified by the configuration file.  If the directory does  not
              exist, it is created and skeleton files are copied.

There are other similar flags as well. For example, the --no-create-home option tells the tool to not create the home directory, even if it doesn't exist. Then there's --shell that you can use to force adduser to use a different shell as the user's login shell, rather than the default specified by the configuration file.

Q6. How to create user or group with custom IDs?

If you want, you can force adduser and addgroup to assign custom user and group IDs while creating a user and a group, respectively. This can be achieved using the --uid and --gid options.

--uid ID
              Force the new userid to be the given number.  adduser will  fail
              if the userid is already taken.
--gid ID
              When creating a group, this option forces the new groupid to  be
              the  given  number.   When creating a user, this option will put
              the user in that group.

Q7. How to make adduser/addgroup emit minimal or maximum information?

To make these tools emit minimum info, use the --quiet command line option. And in case you want these tools to be verbose, use the --debug option. The following screenshot gives a clear idea about the difference between the two:

Adduser command verbosity


Both adduser and addgroup commands have a decent learning curve, but that doesn't mean they are hard to understand. In fact, you can begin with learning the options that help you do your work, and understand others gradually. We have already explained some of the options here. Once you are done with these, head to the common man page for these tools to learn more.

Share this page:

3 Comment(s)