Linux Commands Ubuntu

What is the Newusers Command in Linux/Ubuntu?

What is the Newusers Command in LinuxUbuntu

Ubuntu is popular for having multiple users as it mainly is a Multi-user Operating System. Creating new users is essential for administrators as instead of one user having all the administrative privileges, multiple users are created for more access control and authorization of users. With each user having a separate account, user management can be carried out by the administrator effortlessly and the administrator can then monitor every individual account as well.

In this article, the different methodologies and approaches to creating a user account are explained.

What is the Newusers Command in Linux/Ubuntu?

The “newusers” and the “useradd” are valuable commands in Ubuntu used mostly by administrators to create new users. The new users can be made in Bulk, i.e. Recursively, and a single user at a time. New users can be created in multiple ways and each method for creating a new user or creating multiple users is explained below.

Method 1: Creating New Users With Default Configuration

The “useradd” command can be used to create a new user in Ubuntu with the default configuration. With the default configuration, the newly created user will have the group of the same username, default home directory, and the default “/bin/sh” shell. To create a new user with “useradd”, use the command:

useradd <userName>

In our case, to create a new user “umar” with “useradd”, the command used will be:

sudo useradd umar

The terminal will move to the next line once the user is created indicating the success of user creation:

The new user added can be verified using the command:

cat /etc/passwd

All the users will be displayed in the terminal. Scroll down and you will find the newly created user with the default configuration:

As the new user was created with the default configuration, the password needs to be added for the new user “umar”. The password for the newly created user, in our case “umar”, can be added using the command:

sudo passwd umar

The New Password will be asked in the command line:

Following the addition of a New Password, the command line will ask you to retype the password for confirmation. Once the password matches, it will inform that the new user password has been updated successfully:

Method 2: Creating New Users with Custom Configuration

New users with Custom Configuration can also be created using the “useradd” command. For the Custom Configuration, you need to pass the configuration parameters in the command line:

useradd -s <shell> -m -d <home-directory> -g <groupName> <userName>

Here, the “-s <shell>” is for the users’ login shell, “-m” will create the home directory if it does not exist, and the “-d <home-directory>” is for adding the Custom Home Directory of the user.

In our case, we will create a new user with custom configurations using the “useradd” command. The new user, in our case “hashaam”, will have the custom shell “/bin/sh”, the custom home directory “/home/nyc” and the group “genz”:

sudo useradd -s /bin/sh -m -d /home/nyc -g genz hashaam

The cursor moves to the next line indicating the new user was created successfully:

The newly created user “hashaam” can be verified by using the command:

grep hashaam /etc/passwd

The “grep” will filter the users’ list and return only the details of the user “hashaam”:

Method 3: Creating New Users Collectively

To create New users recursively the “adduser” command is used in Ubuntu. The “adduser” command is more favorable as it asks for the user configuration parameters while creating the new user. The “adduser” command in Ubuntu is used in a simple way using the command followed by the user name of the new user:

adduser <userName>

In our case, to create a new user “mike” using “adduser”, the command used will be:

sudo adduser mike

It will start creating the user and will ask for the user configuration parameters detail one by one:

Once you have added the details, in our case, for the user “mike”, it will ask for confirmation. Enter “Y” to create the new user:

The new user will be created and can be verified using the “grep” command with the user name.

grep mike /etc/passwd

The “grep” command will filter the user list and return only the details of the new user “mike”:

 

Method 4: Creating New Users in Bulk

The “newusers” command is a useful command for creating multiple users in bulk. It makes the process of creating new users unchallenging and time-saving for the administrators. To create new users in bulk, you have to create a new text file first which will have the configuration details of all the new users. In our case, to create a new text file “bulk-users.txt” the nano command is used:

sudo nano bulk-users.txt

This will create the new text file and will open the Text Editor:

Inside the text editor, the configuration of the new users is to be added. The configuration parameters of users as how they are stored in the system are:

<loginName> : <password> : <UID> : <GroupID> : <comment> : <home-directory> : <shell>

In our case, to add three new users “bobby”, “john”, and “aswan” according to the user configuration format, the configuration parameters added in the text editor will be:

bobby:password123:1009:1009:BobbyID:/home/bobby1:/bin/sh
john:password123:1012:1012:JohnID:/home/john1:/bin/sh
aswan:password123:1022:1022:AswanID:/home/aswan1:/bin/sh

Once the new user configurations are added, write them into the text editor using the shortcut key “ctrl+o”:

Hit “Enter” to write the content to the text file and then close the text editor using the “ctrl+x” key. Now, to add these bulk users in Ubuntu use the “newusers” command:

sudo newusers bulk-users.txt

The command line moves to the next line indicating the users are added:

To verify the newly created users, use the “cat” command to list all the users:

cat /etc/passwd

In the users’ list, scroll down to the end and you will see the newly created users. In our case, all three users were created:

Conclusion

The “newusers” and the “adduser” commands are helpful commands for creating new users in Ubuntu. With these commands, the administrator or any sudo user can create new users with either default configuration or custom configuration. These commands can also create new users collectively as well as multiple new users in Bulk. This article has explained the use of both these commands for creating new users in a variety of different ways.

 

Similar Posts