Finding a user account information in Linux is fairly simple if you know the commands. This guide will describe how to accomplish this task.
Linux provides a list of commands that can be used to collect information about users, and we will demonstrate this with the help of the id command and the ‘/etc/passwd’ file.
Unix/Linux-like operating system, UIDs are reserved as shown below in the table.
UID’s | Description |
---|---|
0 | UID 0 is assigned to the root user |
1 to 999 | UIDs 1 to 999 are reserved to the system users |
1000+ | Local user begins from 1000 onwards |
1) Checking user information using id command
The id command stands for identity, which prints real and effective user and group IDs for given user. Every user can fetch their own information by running this command.
$ id uid=1000(linuxgeek) gid=1000(linuxgeek) groups=1000(linuxgeek),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sambashare)
The above output contains three parts. Let’s explain.
Field | Field Value | Description |
---|---|---|
uid | 1000(linuxgeek) | Each user has an identifier (UID) and a name in Linux |
gid | 1000(linuxgeek) | It displays the user’s primary group ID & name |
groups | 1000(linuxgeek),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),120(lpadmin),131(lxd),132(sambashare) | It displays the user’s secondary groups ID & name |
1.1) Checking other user information in Linux
You must be the root user to check other user account information. The root account is a fully privileged user and can check all other users information available on the system.
# id user1 uid=1007(user1) gid=1007(user1) groups=1007(user1)
1.2) How to check if a user is a local account or from Active Directory
If you have integrated a Linux system with Active Directory (AD) for single sign-on (SSO), you may get an output similar to the below one, but the UID & GID information will vary according to your user. The below output evident that the system is integrated with AD and the user information is coming from there.
# id fosstechi uid=1918901106(fosstechi) gid=1918900513(domain users) groups=1918900513(domain users)
2) Finding user information using ‘/etc/passwd’ file
The ‘/etc/passwd’ file is a text file that stores the local user information, such as user’s name, password, user id (UID), group id (GID), user’s home directory and shell. Each user profile consists of separate lines with seven fields as described below.
$ cat /etc/passwd | grep -i linuxgeek linuxgeek:x:1000:1000:2g Admin:/home/linuxgeek:/bin/bash
Let’s attach an image for better understanding.
Let me explain each and every field with details.
Field | Field Value | Description |
---|---|---|
Username | linuxgeek | Name of the user. Allowed characters length should be between 1 to 32. |
Password | x | It indicates that encrypted password is stored at /etc/shadow file. |
User id (UID) | 1000 | It indicates the user ID (UID) each user should be contain unique UID. |
Group id (GID) | 1000 | It indicates the group ID (GID) each group should be contain unique GID is stored at /etc/group file. |
User Information | 2g Admin | It indicates the command field. This field can be used to describe the user information. |
Home Dir | /home/linuxgeek | It indicates the user’s home directory. |
User’s Shell | /bin/bash | It indicates the user’s bash shell. |
Conclusion
In this short article, we have learned how to get the user account information for given UID using the id command. Also, we explained how to find the user information by parsing the /etc/passwd file.