CentOS

How to use the “adduser” command in Linux with examples

How to use the "adduser" command in Linux

This tutorial by Linuxways.net is aimed at helping users understand the basics of the “adduser” command in Linux. It should also provide a guide to help add a new user to an existing Linux machine.

This guide is geared towards novice and intermediate users and contains plenty of images and examples to help them navigate easily. So without further adieu, let’s get started.

Adduser command in Linux

The “adduser” command in Linux allows you to create a new user on a Linux system right from the terminal. With the help of the command, you can create a home directory, modify the configurations, add a password and add a default shell as Bash without having to leave the terminal.

The “adduser” command is similar to the “useradd” command however, the “adduser” command is much more interactive and user friendly when compared to the “useradd” command.

Prerequisites of using the Adduser command

Before you start using the “adduser” command, there are some prerequisites that you must meet. You, of course, you need a system that is currently running Linux. You also need access to the root user or a sudo user to install the “adduser” command.

Installing adduser command

Before using the adduser tool, you must first install it to your Linux distribution. Depending on the specific version, you may need to use specific commands.

For Debian or Ubuntu
# sudo apt-get install adduser
For CentOS or RedHat
# sudo yum install adduser
For Fedora OS
# sudo dnf install adduser
To test if the command is installed correctly use the code below. 
# adduser --version

Once installed, you can start using the “adduser” command. A detailed example on how to use it is given below. 

Examples of how to use the “adduser” command in Linux 

To add a new user

To add a new user, simply type the following command. 

# sudo adduser name_of_user

Replace name_of_user with the exact name of the new user, and a detailed list of things the “adduser” command lets you do will come on the screen.

The command will prompt you to type in your existing Linux password and some other basic questions about the new user. Once you provide the details, a new user will be set up.

To add a system user in a different shell. 

The following command will create a user and will change the default shell to /bin/sh.

# sudo adduser username --shell /bin/sh

Add User Password Options

If you want to override the password or avoid setting up a password during user creation, use the following command. 

# sudo adduser --disabled-login username

Adding a new user with a different configuration file

You can configure a new user from the custom_config file using the following command. It will also create a new custom_config filename configuration.

# adduser username --conf custom_config.conf

Adding a user with a different home directory

If you want to add a new user with a different home directory, use the following command. 

# adduser username --home /home/username/

Adding a new group to the system

Combining the –group syntax with the adduser command will allow you to add a new group in the system. Use the following syntax when prompted:

# sudo adduser --group user_name


You can also add –system option to create a system user and a group with the same name. 

# sudo adduser --group --system any_given_name

To seek assistant if you forget any particular syntax

To remember all the command names can be challenging, even for someone with vast expertise in Linux. So, to display the help section type the command

# adduser -h

It will show a helpful window of all the adduser commands.

Conclusion

The adduser command is a simple and user-friendly tool to quickly add a new user to your Linux system. You still get an array of options of setting up password or allowing root access to the new user. However, if you need more granular control, the “useradd” command may be more handy. Don’t forget to check our other articles for more Linux tips and tricks.

Similar Posts