When working with any Unix machine, it is recommended to run commands as a sub-user, and only to use root when necessary. This means that a basic knowledge of how to create new users and give them proper permissions is required. Here is a step-by-step guide on how to create new users on Linux, how to add a password to those users.

 

CREATING NEW USERS ON LINUX

The first step is to create a new user if you haven’t already done so.


To create a new user run

useradd username


Unless specified in the useradd command, any user that you create will not contain a password.


CREATING PASSWORDS FOR NEW USERS ON LINUX

To add a password to user or to change password run 

passwd username


It is not safe to be operating your VM as root, so in order to make changes from a created user, you need to grant root or sudo privileges to created users.


GRANTING ROOT OR SUDO PRIVILEGES TO USERS

To grant root privileges for a user on Ubuntu or Debian run 

usermod -a -G sudo username


To grant root privileges for a user on CentOS or RedHat run 

usermod -a -G wheel username


CREATING A HOME DIRECTORY ON LINUX

In some cases, a created user may not have a /home directory, or you may want to change the /home directory to another location. 


To change or create a home directory for a user run 

usermod -d /home/username username