How to Create a User with Password and Base Directory in Linux (Ubuntu) Using Terminal Commands

Tiempo de lectura: 2 minutos

Reading Time: 2 minutes

Pixabay photo at Pexel

It’s very simple by following the commands as indicated below:

Once the terminal is open, we will write the command shown below. In it, we can see that the user will be named DevCodeLight and their base directory will be usuarioDevCodeLight. The directory will be located within home.

sudo useradd -d /home/usuarioDevCodeLight -m DevCodeLight
  • -d: Indicates the base directory (whether it exists or not)
  • -m: Creates the user in the directory if it doesn’t exist

Next, we verify that the user has been created correctly with the following command:

cat /etc/passwd

Finally, we need to assign a password to the newly created user as shown below:

sudo passwd DevCodeLight

We enter the administrator’s password and then assign a password to the created user. It will ask us to repeat the password.

To see how to create groups and add the created user to a group, you will find it here

I hope it helps, regards.

Leave a Comment