How to find User account information in Linux

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’sDescription
0UID 0 is assigned to the root user
1 to 999UIDs 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.

FieldField ValueDescription
uid1000(linuxgeek)Each user has an identifier (UID) and a name in Linux
gid1000(linuxgeek)It displays the user’s primary group ID & name
groups1000(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.

FieldField ValueDescription
UsernamelinuxgeekName of the user. Allowed characters length should be between 1 to 32.
PasswordxIt indicates that encrypted password is stored at /etc/shadow file.
User id (UID)1000It indicates the user ID (UID) each user should be contain unique UID.
Group id (GID)1000It indicates the group ID (GID) each group should be contain unique GID is stored at /etc/group file.
User Information2g AdminIt indicates the command field. This field can be used to describe the user information.
Home Dir/home/linuxgeekIt indicates the user’s home directory.
User’s Shell/bin/bashIt 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.

fosstechi

Recent Posts

How to List or Display all Cron Jobs in Linux

Cron is a command-line job scheduler available on Linux operating systems that allows users to…

1 year ago

How to Disable IPv6 on RHEL System

In computing, there are two types of IP addresses, IPv4 and IPv6. By default, IPv6…

1 year ago

How to View Contents of tar.gz File in Linux

A tarball is commonly known as a TAR file, short for tape archive, which is…

1 year ago

How to Create tar.gz File in Linux

A tar archive is a file that stores a collection of directories and files, also…

1 year ago

How to Identify LUN Mapped to VxVM Disk in Linux

On Linux, you can quickly find out how LUNs are mapped to the underlying OS…

1 year ago

How to List Available Package Updates in Ubuntu

Keeping your Ubuntu system up-to-date is critical to ensuring a system's stability and security. This…

1 year ago

This website uses cookies.