Basic guide to Managing Users and Groups in Ubuntu OS

navya , Credit to  volkotech-solutions Nov 20
Creating Users and Group in Ubuntu

Ubuntu provides one unique feature that a single system can have multiple users, so here is a quick guide on how to create users and groups in Ubuntu using terminal.

Pre-requisites:

  • Laptop/Pc with Ubuntu OS installed

  • Active Terminal

If you don’t have Ubuntu on your Laptop/computer and want to install it,  please see this blog below.

https://mycode.blog/naveen-golla/how-install-ubuntu-your-computer

In this blog, I will lead you through the following steps, which can all be done from the command line.

  1. Creating users in ubuntu
  2. Creating a group in ubuntu
  3. Adding users to the group in ubuntu

Creating users in Ubuntu

We create the required number of users in Ubuntu and can assign required permissions. The most basic command for creating users is

useradd [options] nameOfUser.

Let us now try creating users. For example, I’m creating a user named John with access to just the home directory and a unique password, and the command necessary is sudo useradd -m nameOfUser -p password.

To do so, open your terminal using the key ctrl+alt+T and enter the above command with appropriate values.

In the screenshot below, you can see that I have created a user with the name John and password 1234; if you print the current working directory, the path of the new user that you have created will be displayed.

Creating user using Ubuntu terminal

You can now view the updated user info if you check the users in your Ubuntu settings. 

Validating user info using Ubuntu GUI

So, if you list the new user directory and permissions, you’ll see the default permissions. 

Listing users using Ubuntu terminal

So since we’ve created a new user and reviewed the default permissions, let’s see how we can create a group and add users to it.

When you try to log in to your computer, the created user will appear as follows:

Validating user's in Ubuntu login window

With this command sudo usermod -L nameOfUser, you can avoid displaying the newly created user in the login window. 

Removing user in Ubuntu login window using Ubuntu terminal

You didn’t see the user John on the login screen, did you?

Validating user's in Ubuntu login window

Creating a group in Ubuntu

Consider a scenario in which more than one user is included in a project in the same work environment where you can create groups and exchange information. sudo groupadd groupName is the command used to create a group.

Now let us create a group and add users to it. In the screenshot below, you can see that we created a group using the above command, and if we want to verify whether the group is created or not, we have to use the following command.
grep groupName /etc/group.

Creating group using Ubuntu terminal

And clearly, we can see that group volkotech is created, now let’s move to the next step, which is adding users to the group.

Adding users to the group in Ubuntu

So we have a group with the name volkotech and now we can able to add users to the group, the command that is used to add the users to the group is sudo usermod -a -G groupName nameOfUser

Adding users in group using Ubuntu terminal

In the above screenshot, you can see that, as navya is the root user can be added directly, and in the next step the user Naveen is not the user of the current system, so to add that user to the group volkotech, you need to create the user and then add to the group.

Validating user's group using Ubuntu terminal

If you carefully observe the above screenshot, you will see that the first command creates the user, the second command restricts the user’s appearance at the login screen, the third command will add the user to the group, and the fourth command will print the users in the group.

Now if you want to check the position of the user then in the terminal type the following command and see the status.
Command: groups userName 

In the below screenshot,  you can see that we have listed the group and then printed the status of every user in the respective group.

Checking user status using Ubuntu terminal

If we list each and every user present in the current system, we can see the default access file permissions, have a glance at the below screenshot

Validating user permissions using Ubuntu terminal

You can see something before the user name like -rw-r--r-- 1 krishna krishna  807 Feb 25  2020 .profile. Check out the below blog to get about file permissions https://mycode.blog/navya/how-add-file-permissions-ubuntu.

Conclusion :

That’s all for this blog. So,  go ahead and finish the job by creating multiple users and groups, and have fun doing it. I’ll see you in the comment section!

FAQ

How do I list the users in the group?

You can list the users in any group with this simple command grep groupName /etc/group.

How can I list all the users and groups available on my ubuntu computer?

You can list all the user’s present on your computer with this command compgen -u, and for groups use this command compgen -g

Comments

Authors

Read Next