How to List and Manage Users in Linux

29/12/2020
Chưa phân loại
Linux distributions ship with built-in support for multiple user roles and profiles. By using different user accounts and groups, it is possible to make the same system behave differently for different users or restrict access and privileges to certain users.

This article will explain how to create, delete and manage users and groups in Linux (tested with Ubuntu 19.10)

What is a User?

A “user” is an entity who has rights to access and modify a Linux system in full or limited capacity. There can be many users in a typical Linux system. In fact, during the installation of a Linux based OS like Ubuntu, your default user with login and password as well as many system level users are automatically created.

What is a Group?

A “group” is a broad collection of various users in a Linux system. Groups are usually created to define the same set of rules and security policies for each user that falls under them. These groups allow better user organization by restricting privileges and system access.

Difference Between a System User and a Normal User

Normal users and system users are essentially the same. Some people use them for organizational purposes by classifying them on the basis of assigned user IDs (UIDs), as system users and normal users usually have different ID ranges.

Graphical Application for Managing Users and Groups

A “User and Groups” app comes pre-installed by default on most GNOME based distributions. If not, install it in Ubuntu by running the command below:

$ sudo apt install gnome-system-tools

Just launch it from application launcher and click on visible buttons to manage users and groups.

List Users Using Command Line

To see a detailed list of all users on Ubuntu, run one of the following commands:

$ cat /etc/passwd
$ getent passwd

To see only usernames, run the following command:

$ compgen -u

List All Groups

To list all groups, run the command below:

$ groups

Add a New User

To add a new normal user, run the command below (replace “user_name”):

$ sudo adduser “user_name”

To add a new system user, run the command below (replace “user_name”):

$ sudo adduser –system “user_name”

A new home directory will be created for any new user created using the commands above.

Remove an Existing User

To delete a user, run the command below (replace “user_name”):

$ sudo deluser “user_name”

To delete a user along with its home folder, run the command below (replace “user_name”):

$ sudo deluser –remove-home “user_name”

To delete a user along with all files associated with it, run the command below (replace “user_name”):

$ sudo deluser –remove-all-files “user_name”

Add a New User to an Existing Group

To add a new user to an existing group, run the command below (replace “user_name” and “group_name”):

$ sudo adduser “user_name” “group_name”

Remove a User from an Existing Group

To remove a user from an existing group, run the command below (replace “user_name” and “group_name”):

$ sudo deluser “user_name” “group_name”

Rename Existing User

To rename existing user, run the command below (replace “new_name” and “old_name”):

$ sudo usermod -l “new_name” “old_name”

Change Password of an Existing User

To change the password of an existing user, run the command below (replace “user_name”):

$ sudo passwd “user_name”

Create a New Group

To create a new group, run the command below (replace “group_name”):

$ sudo addgroup “group_name”

To create a new system level group, run the command below (replace “group_name”):

$ sudo addgroup –system “group_name”

Delete an Existing Group

To delete an existing group, run the command below (replace “group_name”):

$ sudo delgroup “group_name”

To delete an existing system level group, run the command below (replace “group_name”):

$ sudo delgroup –system “group_name”

Conclusion

These are few commands that you can use to manage users and groups on your system. Be careful when renaming and removing users, as a wrong command can lead to permanent removal of files of another user or may restrict its login. If you want to preserve files of a user, make sure to take a backup of its home directory before deleting the user.

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

Installing OpenStack on CentOS

OpenStack is a full-fledged cloud management software released by RedHat Inc. It is a wildy complicated project with many...
28/12/2020

Docker Compose vs Docker Swarm

Web Apps and Microservices With the container ‘revolution’ apps has grown much more than being just a database and...
29/12/2020

Top 5 Free Benchmarking Tools

Benchmarking is probably of one the most mind-bending and involved process of computer science and technology. They are...
29/12/2020
Bài Viết

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

Dịch Vụ Xây Dựng Hệ Thống Peering Với Internet Exchange (IXP)
04/04/2025

Dịch Vụ Triển Khai VPN Site-to-Site & Remote Access
04/04/2025

Dịch Vụ Thiết Lập Hệ Thống Tường Lửa (Firewall)
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ảo Hóa & Cloud
04/04/2025

Dịch Vụ Triển Khai Hệ Thống Ceph
04/04/2025