Fedora

How to List the User Accounts in Fedora Linux

In this guide, we will showcase how to list all the user accounts in Fedora Linux.

Prerequisites:

To perform the steps that are demonstrated in this guide, you need the following components:

User Accounts in Fedora Linux

Linux is a multi-user system by design. This allows multiple users to connect to a single system and use its resources. To keep everything in check, Linux also comes with a robust permission system that limits what each user can access.

Fedora Linux is a popular Linux distro that is developed by the Fedora Project. It’s a free and open-source operating system that is suitable for workstations, clouds, and containers. It also incorporates the robust multi-user feature that Linux supports.

System and Normal User Accounts

There’s no specific difference between a system account and a normal user account. System accounts are generally created during the installation of the operating system or various packages. Normal users, on the other hand, are generally created by the root (or other users with sudo privilege).

Whenever a user account is created, it’s assigned with a UID. It’s a numeric value that is unique to each user in the system. If it is not specified during creation, the value is automatically selected. The minimum and maximum values of UID are defined in /etc/login.defs:

$ cat /etc/login.defs | grep -E '^UID_MIN|^UID_MAX'

 

Listing the User Accounts

In Linux, the /etc/passwd file contains the list of all the user accounts in the current system.

Listing the Users Using Cat

Check the content of the file:

$ cat /etc/passwd

 

If the list is too long, pipe the output to more or less for easier navigation:

$ cat /etc/passwd | more

 

$ cat /etc/passwd | less

 

The first entry of every single line is the username of the user account. If you’re interested in just the usernames, we can filter it using “cut” or “awk”:

$ cat /etc/passwd | cut -d: -f1

 

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

 

Listing the Users Using Getent

The “getent” command is used to get the entries from Name Service Switch libraries (configured in /etc/nsswitch.conf). We can use it to get a list of user accounts in the system as well.

To get the list of users, run the following command:

$ getent passwd

 

This prints the contents of /etc/passwd. To get the usernames only, we can filter the output using “cut” or “awk”:

$ getent passwd | cut -d: -f1

 

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

 

Using the UID value that is defined in /etc/login.defs, we can also separate the normal user accounts:

$ getent passwd {1000..60000}

 

Managing the User Accounts in Fedora

This section briefly demonstrates how to manage the user accounts in Fedora Linux.

Total User Accounts

To get the total count of the user accounts that are currently in the system, use the following command:

$ cat /etc/passwd | wc -l

 

Searching for an Existing User

To check whether a user account already exists, we can use the following command:

$ getent passwd | awk -F':' '{ print $1}' | grep <username>

 

Creating a New User

To create a new user, use the “useradd” command:

$ sudo useradd -m <username>

 

 

Then, assign a login password to the new user:

$ sudo passwd <username>

 

Deleting an Existing User

To delete an existing user, run the “userdel” command:

$ sudo userdel -r <username>

 

If the processes are running under the user, removing the user may result in error. In that case, use the “killall” command to terminate all the processes first:

$ sudo killall -u <username>

 

$ sudo userdel -r <username>

 

User Group

User groups are used to manage the various user permissions. For example: the ability to access the block devices, run the sudo commands, etc.

By default, a user is part of a primary user group with the same name as the user:

$ groups <username>

 

To add a user to a different user group, use the following command:

$ sudo usermod -aG <user_groups> <username>

 

To remove a user from a user group, use the following command:

$ sudo gpasswd -d <username> <group>

 

Conclusion

We showcased the various ways of listing the user accounts in Fedora Linux. We also briefly demonstrated how to add and remove the user accounts and manage the user permissions through user groups.

Interested in learning more about Fedora Linux? Check out the Fedora sub-category that contains numerous guides on various aspects of Fedora Linux. For example: installing graphics drivers, configuring diskless booting, VNC server, and more.

Happy computing!

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.