How to create user in Linux
In this example we will explain how to create user in Linux and how to protect this user by setting up a password for it, we will demonstrate how to create a user account and not a system account. For this particular example we’ll use CentOS 7 as our main operating system and all the above tasks will be performed using shell prompt.
Connecting to our environment
As we mentioned before will be using shell prompt in our example and we’ll have to initiate a SSH connection in order to connect to our CentOS 7 environment. We can use Putty if we are using Windows OS or Terminal app if we are a MacOS user.
$ ssh user@dummy-environment
Our dummy-environment
can be a public or private IP address, a hostname reachable within your network or a domain name, assuming that one of these are pointing to a CentOS 7 environment (physical server, virtual machine, desktop, laptop etc.).
Becoming root user in Linux
Assuming that we are already connected to our CentOS 7 environment lets go a step further in this exercise by using root account. This isn’t really necessary as we can always impersonate root commands via sudo
if needed and of course if our user has sudo privileges. For a higher learning curve we’ll use the root
account.
$ sudo -I
Creating user account
To create user in Linux we don’t need any special packages installed, just a simple command called adduser
like shown in the example below, lets run that.
# adduser dummyuser
If no error shows up then we’re good, our user has been successfully created. Let’s make sure that our new user profile has been created as well by checking the /home/
directory executing the next command in our shell prompt.
# ls -l /home/
The output should look something similar with this one listed below.
0 drwx------ 2 dummyuser dummyuser 62 Feb 8 13:00 dummyuser
Set up the password
No that we’ve managed to create our dummyuser
Linux user it’s time to protect this account by setting up a password. The password should be no less than 8 characters, it will work but this isn’t really recommended, avoid using simple passwords such as qwerty
or changeme
.
# passwd dummyuser
Once the above command has been executed we’ll be prompted to set up the password, no characters will be displayed on the screen, we just need to type the password and hit Enter on both fields until the confirmation message shows up.
Changing password for user dummyuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Conclusion
In this small tutorial we have learned how to create user in Linux using shell prompt and also how to set up a password for it.