Guides and tutorials

Hundreds of tutorials and step by step guides carefully written by our support team.

How to create new users on linux from the command line

In this manual, we will deal with the following topics:

  • How to create a new user in GNU/Linux operating systems from the command line.
  • How to assign a password to the new user.
  • How to assign or change a 'home' directory to the new user.

Below you will find the steps for each of the mentioned topics.

How to create a new user in GNU/Linux operating systems

In the first place, it will be an indispensable requirement to have SSH/terminal access to an account with superuser permissions. For example, the "root" user account.

Next, we will use the command useradd to create the user. The syntax is the following:

useradd -opciones nombredeusuario 

For the purposes of this manual, we will only consider the "-m" option that allows us to specify whether or not we want to create a "Home" directory with the same name as the user we created.

Examples:

Create a user with home directory: useradd -m nuevousuario

Create a user without home directory: useradd nuevousuario

How to assign a password to the new user

Changing the password of the new user (or any other user of the system) is as easy as executing the following command as superuser.

passwd nombredeusuario

Next we will be asked to enter the password and confirm with the "ENTER" key. Then we will be asked to repeat it for security reasons.

Important: during the process of password assignment, the keyboard will not seem to work, however what happens is that the characters entered are invisible. You should type the password normally, being aware that you simply cannot see what is being written.

How to assign or change a home directory to the new user

If during the process of creating the new user we have not specified a home directory (or if we want to modify the directory of an existing user), we can use the command "usermod".

The syntax is the following:

usermod -m -d /home/directoriodestino/ nombredeusuario

The "-d" option allows you to specify the path of a non-existent directory. It is important that this directory does not exist previously.

The option "-m" allows to indicate that all the content must be moved to the new directory. Useful in the case of an existing user.

Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.
Your privacy is important for us
We use our own cookies for the proper functioning of the site. In addition, third-party cookies are used for analytical purposes only. This information is not associated with any person so that personal identifying data is not stored, but is only information that is collected to identify the session, with the aim of facilitating the analysis of the website. You can change your preferences at any time by entering this website again. For more information about our cookie policy you can visit our Cookies. You can press the "Accept and close" button to give us your consent or you can access more detailed information and manage cookies.