The Complete Guide to add user to linux server

Chukwuemeka Igbokwe
2 min readNov 26, 2019

--

We all are aware about the most popular command called ‘useradd‘ or ‘adduser‘ in Linux. There are times when a Linux System Administrator asked to create user accounts on Linux with some specific properties, limitations or comments.

In Linux, a ‘useradd‘ command is a low-level utility that is used for adding/creating user accounts in Linux and other Unix-like operating systems. The ‘adduser‘ is much similar to useradd command, because it is just a symbolic link to it.

In some other Linux distributions, useradd command may comes with lightly difference version. I suggest you to read your documentation, before using our instructions to create new user accounts in Linux.

When we run ‘useradd‘ command in Linux terminal, it performs following major things:

  1. It edits /etc/passwd, /etc/shadow, /etc/group and /etc/gshadow files for the newly created User account.
  2. Creates and populate a home directory for the new user.
  3. Sets permissions and ownerships to home directory.

Basic syntax of command is:

useradd [options] USERNAME

1. How to Add a New User in Linux

Before we start, please replace USERNAME with the name of the user you are creating and also replace YOUR-IP-ADDRESS with your server ip address.

To add/create a new user, all you have to do is ‘useradd‘ or ‘adduser‘ with ‘username’. The ‘username’ is a user login name, that is used by user to login into the system.

Only one user can be added and that username must be unique (different from other username already exists on the system).

For example, to add a new user called ‘lexigbokwe‘, use the following command.

useradd lexigbokwe

When we add a new user in Linux with ‘useradd‘ command it gets created in locked state and to unlock that user account, we need to set a password for that account with ‘passwd‘ command.

[root@lexigbokwe ~]# passwd USERNAME
Changing password for user USERNAME.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Once a new user is created, it’s entry is automatically added to the ‘/etc/passwd‘ file.

The next thing is to make the user a sudoer if you want the user to perform sudo related actions.

usermod -aG admin USERNAME

Once you’ve done that, you now need to switch to the created user with the following command.

sudo su USERNAME

You should now be logged in as the user. We now have to do the following, which are

  1. create .ssh folder
cd ~ 
mkdir .ssh

2. Cd into .ssh and create an authorized_keys file.

vim authorized_keys

3. peaste your system ssh key inside the authorized_keys file you created.

4. Exit from the user including the root user.

5. finally run the following code in your local system

ssh -i ~/.ssh/id_server USERNAME@YOUR-IP-ADDRESS

--

--

No responses yet