CentOS – Add User – from Terminal window

We can use commands from the terminal window or graphical user interface (GUI) to add new user accounts to CentOS-based systems. In this article, we will look into creating user accounts in CentOS using commands from a terminal window.

Step 1. You should log in to the system as a root user or the user with root access privileges. It is always a good practice to log in as a normal user and then take up the superuser privileges using su command.

Let’s start with login as a normal user. I logged in as a normal user ‘malin’ on my “CentOS 64-bit Operating System”.

Step 2. Once logged in into the system; open the Terminal window and type the below command at the command prompt to add the new user account.

useradd <user name>

Where <user name> is the name of the user account we want to add. If the user account doesn’t exist in the system, it will add the user account to the system. Otherwise, this command will throw the below message.

useradd: user '<user name>' already exists

But when I tried on my system I got the below message:

[malin@localhost ~]$ useradd malin
bash: /usr/sbin/useradd: Permission denied
[malin@localhost ~]$

Why it is showing the ‘Permission denied’ message? Because we don’t have permission to run the above command on the system. Remember that we logged in as a normal user instead of a superuser. Now, what do we need to do? It is simple; just we have to run the above command as a superuser.

Step 3. We need to run the above ‘useradd’ command as a superuser. To do this, use the below command at the shell prompt:

[malin@localhost ~]$ su
Password:

Type the superuser password in the “Password:” entry. Once we provided the correct superuser password; the shell will run with superuser privileges. So, the currently logged-in user substitutes as a superuser.

Step 4. Now we will type again the ‘useradd’ command at the shell prompt.

[root@localhost malin]# useradd sampleuser
[root@localhost malin]#

‘sampleuser’ is the name of the user we have created from the above command. We didn’t see any messages; which means, the user account successfully created.

Step 5. Can we log in as a new user? Actually, we can not log in as new users. Because we need to set a password for the new user. If we try to log in as a new user, CentOS will through an “Authentication failure” error.

So, we must set the password for the new user account. Below is the command to set the password for the user:

passwd <user name>

Where <user name> is the name of the user. Let’s set the password for our new user ‘sampleuser’.

[root@localhost malin]# passwd sampleuser
Changing password for user sampleuser.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost malin]# 

When we use ‘passwd’ command to set the password for the user, it will prompt for “New password:”. Once we enter the password, it will ask again for “Retype new password:” to confirm the password. Once both the passwords are matched, it will update the password for the user.

From the above command, we have successfully provided a password for our new user ‘sampleuser’.

Now we can log in as a new user account ‘sampleuser’ to our CentOS-based systems.

We can even specify some default permissions when creating the user. Below is the command to display the list of default permissions applied to the user:

[root@localhost malin]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@localhost malin]#

I am closing this Article here. Will discuss more in the upcoming Articles.
// Malin

CentOS – Add User – from Terminal window

Leave a Reply

Your email address will not be published.

Scroll to top