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

JMap and JStack Tutorial

For any java delopers Jmap and Jstack are two important utility programs that can be used to debug issues, or understand...
28/12/2020

Top 5 Vulnerability Scanning Tools

The process of recognition, categorization and mitigation of vulnerabilities present in a network or application is called...
29/12/2020

Installing Adobe Photoshop on Linux

Linux has long been widely used for servers and has just not been as often considered for using in desktops. However, over...
29/12/2020
Bài Viết

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

Các tiện ích và công cụ để quản lý proxy.
27/02/2023

Các lỗi thường gặp khi sử dụng proxy và cách khắc phục chúng.
27/02/2023

Tác động của việc sử dụng proxy đến tốc độ kết nối internet của bạn.
27/02/2023

Các cách để kiểm tra tốc độ và độ ổn định của proxy.
27/02/2023

Lý do tại sao bạn nên sử dụng proxy khi truy cập web đen
27/02/2023