Ubuntu User Management

Ubuntu User Management

User management is an important part of any Ubuntu/Linux system administrator’s job. It is also one of the most common jobs you will ever do as a Linux sysadmin.   In this article I will show you how to do basic user and group management on Ubuntu.

I will cover the following topics in this article:

  • Add a new user
  • Add a new group
  • Add a user to a group
  • Remove a user from a group
  • Remove a group
  • Remove a user
  • Change password of a user
  • List all the users of the system
  • List all the groups of the system
  • List all the users in a specific group

So let’s get started.

Adding a User on Ubuntu:

You can easily create a new user on Ubuntu from the command line. The recommended way to create new users on Ubuntu operating system is the ‘adduser’ command.

With add user command, you can either create a normal user or a system user. The difference between a normal user and a system user is that the system user can’t login to the system while the normal user can.

To add a normal user ‘lizzie’, run the following command:

$ sudo adduser lizzie

To add a system user ‘lizzie’, run the following command:

$ sudo adduser –system lizzie

I will just add a normal user ‘lizzie’ here.

‘adduser’ command should ask you for the login password. Enter a login password and press <Enter>. It should ask you to retype the login password. Retype the password and press <Enter> again.

Now ‘adduser’ command should ask you for some personal information like Full Name, Room Number, Work Phone, Home Phone etc. Just fill in the details and press <Enter> as you go.

Once everything is done, press ‘y’ and press <Enter>. The new user ‘lizzie’ should be created.

Now you can login as ‘lizzie’ using the following command:

$ su – lizzie

You can see that I am now logged in as ‘lizzie’.


Adding a Group on Ubuntu:

You can add a new group on Ubuntu using the ‘addgroup’ command.

To add a group ‘student’, run the following command:

$ sudo addgroup student

You can see that the group ‘student’ was added.


Adding a User to a Group on Ubuntu:

You can also add a user to a specific group. Earlier I create a new user ‘lizzie’ and a new group ‘student’. Now let’s add ‘lizzie’ to the ‘student’ group.

Run the following command to add ‘lizzie’ to ‘student’ group:

$ sudo usermod -aG student lizzie

‘lizzie’ was added to ‘student’ group.

You can login as ‘lizzie’ and run the following command to verify that:

$ groups

You can see that after I added ‘lizzie’ to the group, I logged out and logged back in and the ‘groups’ command shows ‘student’ as lizzie’s group.


Removing a User from a Group on Ubuntu:

We can use the ‘deluser’ command to remove a specific user from a specific group. Now let’s remove ‘lizzie’ from the ‘student’ group.

Run the following command:

$ sudo deluser lizzie student

You can see that ‘lizzie’ was removed from the ‘student’ group.

You can also use the ‘groups’ command before and after the ‘lizzie’ was removed from the ‘student’ group and verify that the group was removed.

$ groups


Removing a User on Ubuntu:

You can remove a user using ‘deluser’ command. Let’s remove the user ‘lizzie’ that we created earlier.

If you want to keep lizzie’s home directory and remove user ‘lizzie’, run the following command:

$ sudo deluser lizzie

You can also remove user ‘lizzie’ and her home directory with the following command:

$ sudo deluser –remove-home lizzie

I am going to remove ‘lizzie’ and her home directory.

You can see that, the user ‘lizzie’ was removed.

You can see that lizzie’s home directory was also removed.


Deleting a Group on Ubuntu:

You can remove a group on Ubuntu with ‘delgroup’ command. Let’s remove the ‘student’ group we created earlier.

To delete group ‘student’ run the following command:

$ sudo delgroup student

You can see that the ‘student’ group was removed.


Changing the Password of a User:

You can change the password of a user with ‘passwd’ command.

You can change the password of the user you’re currently logged in as with the following command:

$ passwd

You can also change the password of any user as root with the following command:

$ sudo passwd USERNAME

You can see that the password of user ‘shovon’ was changed.

Changing the password with root privileges is a lot easier, and it won’t check whether the password is secure or not. Root user can add weak password to any user. You know, root can do anything!


Listing All Users on Ubuntu:

You can list all the available users on Ubuntu with the following command:

$ cut –delimiter=: –fields=1 /etc/passwd

You can see that all the users of my computer is listed as shown in the screenshot.


Listing All Groups on Ubuntu:

You can run the following command to list all the available group of your Ubuntu computer:

$ cut –delimiter=: –fields=1 /etc/group

You can see that all the available groups of my computer was listed as shown in the screenshot.


Listing All Users in a Group on Ubuntu:

You can list all the users in a specific group on Ubuntu with the following command:

$ cat /etc/group | cut –delimiter=: –fields=1,4 | grep GROUPNAME

You can see that I listed all the users of ‘sudo’ group. ‘shovon’ and ‘jessie’ are the members/users of group ‘sudo’ as shown in the screenshot.

So that’s how you do basic user and group management on Ubuntu. Thanks for reading this article.

Related Posts
Leave a Reply

Your email address will not be published.Required fields are marked *