Before starting the tutorial, don't you have a Cloud Linux server? Don't worry! With just one click, you can easily deploy it with SW Hosting.
cta:cloud_so
Below you will find the steps to create new users on linux from the command line.
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 -options username
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 newuser
Create a user without home
directory:
useradd newuser
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 username
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.
info 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.
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/destinationdirectory/ username
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.
If we want to delete a user we will do it with an account with superuser permissions. For example, the root
user account.
We will use the userdel
command with the following syntax:
userdel -options username
Most of the time, the -r
option is used to delete the main directory and the user's mail queue, leaving the command as follows:
userdel -r username
For example we are going to create a user called usertest
with its own home
, then we will assign a password (which will not be seen on the screen for security reasons of the operating system itself), later we will change that user and see what is the directory in the one we entered when making the change. Finally we are going to list the user's directory to see with what permissions it has been created:
Remember that if you do not yet have a Cloud server with a Linux operating system, you can easily deploy it with SW Hosting.
cta:cloud_so