How to create user and add user to group in Linux

Alex Alex 09 September
How to create user and add user to group in Linux

Let's say that you want to add a user to root privileges. One of the reasons you might want to do this is if you don't want to provide someone with the root password, but want them to have access to root level privileges. You could create a separate user with a different password. Another reason for creating a separate user might be for logging purposes. If, let's say, everyone is logging in as the root user, then you won't be able to tell, in the logs, who is performing what action. So, In this example I will show you how to create, add, and grant root user privileges for that user.

First, you will need to create a user. So inside your server's terminal. Adding a user is fairly simple. The command for adding a user is adduser space and then whatever you want the username to be.

[email protected]:~# adduser alex
Adding user `alex' ...
Adding new group `alex' (1001) ...
Adding new user `alex' (1001) with group `alex' ...
Creating home directory `/home/alex' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for alex
Enter the new value, or press ENTER for the default
	Full Name []: Alex
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] Y

In this example I'll be using the username alex. You'll be prompted to create a password for the username alex. So, add a password that you want. Make sure the password is strong for security purposes. Next, you'll be prompted to enter in username information. So, you have a choice here. You can either fill in this information or skip it, it's really what you prefer. And now the user is created!

The next step is to grant alex root access. This step consists of one command. On the same command line you'll type

usermod -aG sudo alex 

Now sudo is just the root user group, it's called the sudo group. So this will add user alex to group sudo. Lastly, you'll want to verify that the user privileges have been added correctly. You want to type

su - alex 

Enter the root user into the root level. Another way to check that the user has been added to the sudo group is to run the following command

[email protected]:~# grep '^sudo' /etc/group 
sudo:x:27:alex

And you can see that the user is here listed in that group. Now you have successfully added a user and granted it root level privileges. 

If you don't need this user account anymore, you can delete it using command

deluser alex

Comments (0)

    No comments yet

You must be logged in to comment.

Sign In / Sign Up