In this article we’ll be explaining what these terms mean, why they’re important, and answering a common question – how to list Linux users and groups in Ubuntu with the command prompt.

It doesn’t take long once you’ve dived into Linux systems before you encounter words such as ‘root’ and ‘sudo’, which aren’t at first glance entirely easy to understand.

But first, let’s discuss the difference between root user, system user, and regular user on Linux.

What are the 3 types of users in Linux?

Most people are familiar with two types of user accounts on Linux, but did you know that there are actually three different types of users? Let’s see what each one of them does:

  1. Root User: The root user, also known as the superuser, has the highest level of access to the system. This user can read, write, and execute any file, and can perform administrative tasks such as creating, deleting, or modifying accounts, changing ownership of files, and managing system-wide settings. For example, the root user can use the sudo command to execute commands with administrative privileges.
  2. System Users: System users are created by the operating system during installation for running system processes and services. These users have fewer privileges than the root user and are typically used to run non-interactive or background processes. For instance, the www-data user in Ubuntu is a system user that runs the Apache web server.
  3. Regular Users: Regular users are the standard users who use the system for daily tasks. They have the least privileges and can only read, write, or execute files in their home directory. These users can’t access other users’ files or system files without appropriate permissions. For example, a regular user can create and edit files in their home directory, but cannot modify system files located in /etc or /var.

What is the /etc/passwd File in Linux?

The /etc/passwd file is a key file in Linux that contains information about different user and system accounts present on that system. Each line in the /etc/passwd file represents a single user account and contains seven fields separated by colons (:). Here’s a brief overview of these fields:

  1. Username: This is the name of the user. It should be unique and is used for logging in.
  2. Password Indicator: In modern Linux distributions, this field is usually set to x. The actual hashed password is stored in the /etc/shadow file, which has stricter access controls.
  3. User ID (UID): This is a unique numerical ID assigned to the user. The root user always has a UID of 0.
  4. Group ID (GID): This is the numerical ID of the user’s primary group. The group details are stored in the /etc/group file.
  5. Comment/Description/User Info: This field is optional and can contain extra information about the user, such as their full name.
  6. Home Directory: This is the absolute path to the user’s home directory, where their personal files are stored.
  7. Shell: This is the absolute path to the shell that is started whenever the user logs in.

Suggested Read: CentOS vs Ubuntu – Which One Should You Choose in 2024? 

How to List Users in Linux?

As we mentioned above, the /etc/passwd file contains a list of all the users on a Linux computer, and since this file can be read by any user, we can open it using various tools to see a list of all the users in Linux.

Method 1: List Users Using the cat Command

The cat command in Linux prints the entire contents of a file in the Linux terminal, and so you can use the following command to display the content of /etc/passwd file:

cat /etc/passwd
view linux users

Method 2: List Users Using “less” or “more”

The “less” and “more” commands are very similar – they both allow you to peek inside a file without actually printing its contents in the terminal. If the list of users is long, you can use either the less or more command for easier navigation:

less /etc/passwd
more /etc/passwd

Method 3: How to List Users Using the awk Command

The awk command provides you with the option to perform pattern matching and processing on the specified file. You can use this utility to list users by filtering the /etc/passwd file using the following command:

awk -F: '{ print $1}' /etc/passwd

Method 4: List Users Using the getent Command

The getent command displays entries from databases configured in the /etc/nsswitch.conf file, including the passwd database which contains user information. To get a list of all users, you can use the following command:

getent passwd

Suggested read: Pipes vs Xargs: Which One To Use When Writing Bash Scripts In Linux 

What are Linux Groups?

Simply put, a group is a collection of Linux users that makes it easier to collectively manage the permissions and privileges for each user in the group.

In Linux, each user can belong to one or more groups, and when a user is part of a group, they inherit the permissions and privileges of that group. This system allows administrators to manage multiple users’ permissions simultaneously.

Let’s try to imagine a Linux system as a large office building to understand the concept of groups. In this building, there are different departments such as HR, Finance, Marketing, etc. Each department is like a group in Linux.

Now, each department will have employees working in it, and these employees correspond to a user in Linux. An employee can belong to multiple departments, just like a user can belong to multiple groups in Linux.

In this building, each department has its own resources and access permissions. For example, only HR employees can access HR files, only Finance employees can access financial data, and so on. This is similar to how file permissions work in Linux – when a user is part of a group, they inherit the permissions of that group.

This way, Linux groups help in managing permissions and access control efficiently, especially in environments where there are many users. 

Suggested Read: How to Find Most Used Disk Space Directories and Files in Linux 

How to List All Groups in Linux?

There are multiple ways to list groups in Linux, let’s take a look at each one of them:

Method 1: Use the groups Command

In Linux, you can list all the groups that the current user is a member of by simply using the groups command (without any options) as shown below.


Method 2: List all Groups Using the /etc/group File

As the name describes, the /etc/group file contains information about all the groups on the system. You can use the cat command to display its content:

cat /etc/group

Method 3: List All Group Names Using The cut Command

The cut command in Linux provides simple tools to view and process certain sections of a text file and display its contents to the terminal. You can use the cut command to display only the group names from the /etc/group file:

cut -d: -f1 /etc/group

Method 4: List All Groups Using The getent Command

As we mentioned before, the getent command displays information from databases configured in /etc/nsswitch.conf file, including the group database which contains group information. To view a list of all the groups present on a Linux computer, you can use the following command:

getent group

Suggested read: How to Change/Reset MySQL Root Password on Ubuntu Linux? 

Wrapping Up

In this post, we’ve explained how Linux users and groups work, as well as how organizing the accounts in a logical structure makes it easier for the administrators to manage and maintain the permissions. 

While it is easy to grant permissions to any user on your system, it’s important to keep in mind that misuse of user privileges, especially the root user, can lead to system instability or security vulnerabilities. Therefore, we recommend you only grant the level of access necessary to perform a task.

While managing the accounts and permissions in Linux might sound complicated, you don’t need to be a Linux expert to do so. RunCloud simplifies the process, making it easy to manage your website and server with a single click. 

So why wait? Start making your website management effortless. Sign up for RunCloud today!

FAQ on Linux Users and Groups

How to create and delete a group in Linux?

To create a group, use the groupadd command followed by the name of the group. For example, to create a group named ‘developers’:
sudo groupadd developers
To delete a group, use the groupdel command followed by the name of the group. For example, to delete the ‘developers’ group:
sudo groupdel developers

What is the chmod 777 command?

The chmod 777 command changes the permissions of a file or directory to be fully open to all users. The three digits represent the permissions for the owner, group, and others, respectively. Each digit is the sum of read (4), write (2), and execute (1) permissions. So, ‘7’ gives full permissions.
chmod 777 filename

What is getent command in Linux?

The getent command in Linux is a tool that helps users retrieve entries from a number of important text files called databases; this includes the passwd and group databases, which store user information. 
Here are some examples of how to use the getent command:
To fetch the list of user accounts on a Linux system (stored in a database known as passwd), you can use the command getent passwd.
If you want to fetch details for a particular user, for example, a user called naman, then you can use the command getent passwd naman.
If you want to fetch a list of group accounts on a Unix system (stored in a database called group), then you can use the command getent group.

Which command lists all users currently on the system in Linux?

The who command can be used to list all users currently logged into the system: who

What are Linux system users?

In Linux, there are a few user accounts that are automatically created by the system to perform background tasks. These users don’t have a password and can’t log in to interact with the computer – they are only used to grant a specific set of privileges to a particular tool or process.

How do I know if I am a root user?

You can use the whoami command to check if you are the root user:
whoami If the output is ‘root’, then you are the root user.

What is the sudo code?

In Linux, sudo is a command that allows users to run programs with the security privileges of another user (by default, the superuser). It stands for “superuser do”. For example, to run the ls command as superuser:
sudo ls