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:
-
- A properly-configured Fedora Linux system
- Access to a non-root user with sudo privilege
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:
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:
If the list is too long, pipe the output to more or less for easier navigation:
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”:
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:
This prints the contents of /etc/passwd. To get the usernames only, we can filter the output using “cut” or “awk”:
Using the UID value that is defined in /etc/login.defs, we can also separate the normal user accounts:
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:
Searching for an Existing User
To check whether a user account already exists, we can use the following command:
Creating a New User
To create a new user, use the “useradd” command:
Then, assign a login password to the new user:
Deleting an Existing User
To delete an existing user, run the “userdel” command:
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:
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:
To add a user to a different user group, use the following command:
To remove a user from a user group, use the following command:
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!