Ubuntu User Management

28/12/2020

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.

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

Mine Etherium With Ethminer on Ubuntu

Introduction Digital cryptocurrency is not a new topic in the technology world due to its widespread usage. For some time,...
12/02/2020

LVM Ubuntu Tutorial

LVM or Logical Volume Manager makes management of disk space on a Linux machine easier to manage.  Features of LVM include: Create,...
28/12/2020

How to Shutdown Ubuntu 18.04

It doesn’t matter how silly it sounds but shutdown is a major part of our computing. You definitely want to shut down...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024

Thuê mua IPv4 giá rẻ, tốc độ nhanh, uy tín #1
28/05/2024

Thuê địa chỉ IPv4 IPv6 trọn gói ở đâu chất lượng, giá RẺ nhất?
27/05/2024