e Learning

How to Create User in CentOS 7

In CentOS 7 we can use the useradd command in the terminal to add new user to the system. If you are using CentOS 7 Graphical Desktop you can also use user manager software which is a graphical user interface.

Adding Users with useradd command

Easiest way to create user in CentOS 7 is to use the useradd command from the CentOS command line.

useradd loginname

Login name cannot have space and cannot be started with special characters. Even though you can use uppercase it always recommended to use all simple cases to avoid any confusion.

After creating the user, we need to set up the user password using the passwd command because without the password new user cannot log in to the server.

passwd loginname

Also remember that, to execute useradd command you need to have either root access or sudo privileges.

Example 1

Let’s add a new user to our CentOS 7 server. Name of the new user going to be josh.

sudo useradd josh

sudo passwd josh

create user in centos 7

Create user with custom home directory

Every Linux user by default have a home folder by their name to store their personnel files and user specific configuration files. By default home folder will be created inside the /home directory. But if we want we can specify custom home directory location and name using -d option with the centos useradd command.

useradd -m -d /pathto/home loginname

Notice we also use -m option when we specify the custom home directory. with -m option home directory will be automatically created if it does not exist already.

Example 2

In this example, we will see how to create user in centos 7 with a custom home directory. So let’s add a user called john and johns home directory going to be /var/johnhome.

sudo useradd -m -d /var/johnhome john

sudo passwd john

Create user with custom home directory CentOS 7

As I mentioned in the beginning of the tutorial you can also use the user manager graphical interface if you are using CentOS 7 Desktop. Just Go to Applications > System Tools > Settings > Users.

CentOS 7 add user gui

From there also you can add new users to the CentOS 7 System. But I would always recommend to use the command line, because it is so efficient and very very easier than the GUI.