25 C
Jaipur
Friday, November 27, 2020

How to List All Users in a Linux System – Linux Hint

Must read

Sony is Permanently Banning PS5 Owners For Selling Their PlayStation Plus Collection

Sony offers access to 20 PlayStation 4 games through PlayStation Plus Collection, a new benefit to PlayStation Plus subscribers with PlayStation 5. The company...

cPanel 2FA Bypass Exposes Tens of Millions of Websites to Hack

Digital Defense, Inc., a leader in vulnerability and threat management solutions, announced that its Vulnerability Research Team (VRT) exposed a previously undisclosed vulnerability affecting the cPanel &...

At any given time, multiple users can operate a single computer system. However, with such shared systems, a system administrator must take the proper security measures so that one user cannot breach the privacy of another by, for example, applying an access control mechanism that specifies the privileges of each user.

At times, a change in user privileges might be necessary. For example, a user might need his or her privileges extended for a certain task, or a ability of a certain user to access the system may have to be revoked entirely. In such scenarios, it is important for the system administrator to have complete knowledge of all users of the system.

In this article, we explore the methods used to list the users of a Linux system. Both graphical user interface (GUI)-based methods and command line interface (CLI)-based methods can be used for this task; however, this article focuses on four terminal-based methods.

Note: While the methods discussed below are carried out on a Linux Mint 20 system, you can use the Linux distribution of your choosing.

Method # 1: The “cat” command

To use the “cat” command to list all users in a Linux system, the following steps should be performed in order:

Launch the terminal.


Use the “cat” command to list all the users on the terminal to display all the user account details and passwords stored in the /etc/passwd file of the Linux system.


As shown below, running this command will display the usernames, as well as some additional information. You can scroll through this list to view all the users of the Linux system.

Method # 2: The “awk” command

The “awk” command is helpful if you want to display usernames only, which may be useful if you do not need all the technical details returned with the “cat” command. To use this command to list all users in a Linux system, the following steps should be performed in order:

  • Launch the terminal.
  • Run the following command:

$ awk –F: ‘{ print $1}/etc/passwd


When you run this command in your terminal, only the usernames will be returned. This list includes all the users of the Linux system.

Method # 3: The “compgen” command

Like the “awk” command, this command is used to display only usernames, ignoring all other details. To use the “compgen” command to list all users of the Linux system, the following steps should be performed in order:

  • Launch the terminal.
  • Run the following command:


This command will return all the usernames associated with your Linux operating system.

Method # 4: The “getent” command

The output of the “getent” command is very similar to that of the “cat” command, as it displays a lot of details along with the usernames. To use the “getent” command to list all users in the Linux system, the following steps should be performed in order:

  • Launch the terminal.
  • Run the following command:


This command will list all the users of your Linux system, as well as some other details, as shown in the image below.

Conclusion

Depending on your requirements, you can choose from the four commands discussed in this article to obtain a list of users. Two of these methods, in addition to listing all the users of your Linux system, also provide some important details for all of user accounts.

There are variations of these commands that you can experiment with to suit your needs. However, such variations are beyond the scope of this article. The methods we discussed herein will allow you to list all the users of your Linux system. I hope this article helped you to better understanding this topic.

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

Sony is Permanently Banning PS5 Owners For Selling Their PlayStation Plus Collection

Sony offers access to 20 PlayStation 4 games through PlayStation Plus Collection, a new benefit to PlayStation Plus subscribers with PlayStation 5. The company...

cPanel 2FA Bypass Exposes Tens of Millions of Websites to Hack

Digital Defense, Inc., a leader in vulnerability and threat management solutions, announced that its Vulnerability Research Team (VRT) exposed a previously undisclosed vulnerability affecting the cPanel &...