Raspberry Pi

How to List Users in Raspberry Pi

Getting to know about the other users active on Linux systems is important as it helps in managing the system resources and giving permissions to the other users. Raspberry Pi is also a Linux based system and multiple users might be needed in case of operating any device using Raspberry Pi. So, there are multiple ways to get the list of users registered with Raspberry Pi and this guide gives some of them in quite a detailed way.

Finding the list of users in Raspberry Pi

There are multiple ways to get the list of users added in Raspberry Pi and some of them are:

1: Using getent Command

One way to get the list of the users in the Raspberry Pi is by using the getent command, and following are the ways to use this command:

To get the information about a specific user

Use the following command to get the information about any specific user:

$ getent passwd jhon

Graphical user interface, text, application Description automatically generated

To only get the name of the users

In Raspberry Pi the getent command with awk can be used only if the list of names of the users is required:

$ getent passwd | awk -F ':' '{print $1}'

Graphical user interface, text Description automatically generated

To sort out the users within specific range

A specific range can be given to sort out the list of specific users with no additional information falling under this range using awk with getent command:

getent passwd {1000..6000} | awk -F ":" '/home/ {print $1}' | sort

Graphical user interface, text Description automatically generated

To sort out the users within specific range along with their directories

If the list of the directories of the users along with the path of their home directory is required that fall under specific range, then use:

$ getent passwd {1000..6000}

2: Using awk Command

Using the awk is also another way to get the list of users in Raspberry Pi:

$ awk -F ":" '/home/ {print $1}' /etc/passwd | sort

Graphical user interface, text Description automatically generated

3: Using cat Command

There are two ways to get the list of users of Raspberry Pi using the cat command:

Reading all the lines of passwd file

The passwd file is present in all the Linux based system as it contains the all the users that have the access of the system, so use the cate command to get all the data of the passwd file:

$ cat /etc/passwd

Getting the list of users with home directory

Adding a filter of home using the grep command with cat will get the data of the users that are placed in the home directory of the Raspberry Pi along with their names and directory path:

$ cat /etc/passwd | grep home

Text Description automatically generated

4: Using lslogins Command

The lslogin command can be used to get the data on the user’s login information along with their personal details:

$ lslogins -u

5: Using GUI

Finally, from the desktop mode the list of all the users of Raspberry Pi can be found by opening the File Manager and then click on the home folder where all the users of Raspberry Pi can be found:

Conclusion

To know the details of the users that have access to the Raspberry Pi can pave the way in managing and monitoring the system effectively. There are several ways to get the list of users registered with Raspberry Pi and 5 of them are mentioned in this guide.

About the author

Aaliyan Javaid

I am an electrical engineer and a technical blogger. My keen interest in embedded systems has led me to write and share my knowledge about them.