How to use the Linux adduser command ?

Linux

The Linux adduser command is an easy to use utility that allows users to add new users to a Linux system. It is an essential tool for system administrators who need to manage user accounts in a Linux system. The adduser command can be used to create new user accounts, set their passwords, and assign them to groups.

Here at Fixwebnode, we will discuss how to use the adduser command with practical examples. We will also discuss its options.

 

What is syntax for adduser command ?

The syntax of the adduser command is as follows:

$ adduser [options] username

 

adduser command Options

The adduser command has a number of features and options. These features and options can be used to customize the user accounts that are created. 

Some of the options of the adduser command include:

  • -g: Used to assign the user to a specific group.
  • -G, --groups <group[,group]> : Sets the secondary groups for the user.
  • -d: Used to specify the user’s home directory.
  • -s: Used to specify the user’s shell.
  • -e: Used to specify the user’s expiration date.
  • -f: Used to specify the user’s full name.
  • -u: Used to specify the user’s UID (User ID).
  • -m, --create-home : Creates the user's home directory.
  • -c, --comment <comment> : Sets the user's comment (GECOS field).

 

Installing adduser on Linux

The adduser command is usually included in the default installation of Linux distributions like Debian, Ubuntu, CentOS, and Red Hat. However, if it isn't available in your system, you can install it using your package manager.

1. Debian/Ubuntu

On Debian and Ubuntu systems, you can install the adduser command using the apt package manager. To do so, run the following command as root:

$ apt-get install adduser

 

2. CentOS/Red Hat

On CentOS and Red Hat systems, you can install the adduser command using the yum package manager. To do so, run the following command as root:

$ yum install adduser

 

Examples of Using the adduser Command

The adduser command is used to add new users to a Linux system. To use the command, you must first open a terminal window. Once the terminal window is open, you can use the adduser command to create a new user account.

 

1. For example, to add a new user named “John” to your system, you can use the following command:

$ adduser John

This command will prompt you to enter a password for the new user. Once the password is entered, the adduser command will create the user account and assign it to the default group.

 

2. You can also assign the user to a specific group by using the -g flag. For example, to assign the user to the “developers” group, you can use the following command:

$ adduser -g developers John

 

3. The adduser command can also be used to set the user’s home directory. The -d flag is used to specify the home directory for the user. For example, to set the home directory for the user to “/home/John”, you can use the following command:

$ adduser -d /home/John John

 

4. The adduser command can also be used to set the user’s shell. The -s flag is used to specify the shell for the user. For example, to set the shell for the user to “/bin/bash”, you can use the following command:

$ adduser -s /bin/bash John

 

[Need Linux system support ? We are here. ]

 


Conclusion

This article covers how to use the Linux adduser command with examples. We also discussed its features and options. In fact, The adduser command is a powerful tool for system administrators who need to manage user accounts in a Linux system.

Explore:
Your Cart