The Linux core toolset provides us with some commands to view user-related information.

Print User Identity

We can use the id command to view the user’s ID, name, user’s group ID and name, etc:

1
id
img

By default, id output the real user ID, real group ID, effective user ID (if different from the real user ID), effective group ID(if different from the real group ID), and supplement group IDs

If we add the -u option, the command will only output the user’s ID:

1
id -u    # This is equivalent to id --user
img

Output the user's ID

If we add the -g option, the command will only output the group ID:

1
id -g    # This is equivalent to id --group
img

Output the user's group ID

If we add the -G option, the command will only output the supplementary groups’ ID:

1
id -G    # This is equivalent to id --groups
img

Output the user's group ID and supplementary groups

If we add the -un, -gn or -Gn option, the command will only output the user’s name, group name, and supplementary group’s name:

1
2
3
id -un    # This is equivalent to id -u --name
id -gn    # This is equivalent to id -g --name
id -Gn    # This is equivalent to id -G --name
img

Output the user's name, group name and supplementary group name

If we add the -ur, -gr or -Gr option, the command will only output the user’s real ID, group real ID, and supplementary group’s real ID:

1
2
3
id -ur    # This is equivalent to id -u --real
id -gr    # This is equivalent to id -g --real
id -Gr    # This is equivalent to id -G --real
img

Output the user's real ID, group real ID, and supplementary group's real ID

If we add the -Z option, the command will only output the user’s security context:

1
id -Z    # This is equivalent to id --context
img

Output the user's security context

Print Current Login Name

We can use logname command to display the user name of the current login:

1
logname
img

Output the user's login name

Print Who is Currently Logged in

We can use who command to display the logged in user names and other login details:

1
who
img

Output the information about users who are currently logged on

Print Effective User ID

We can use whoami command to display the effective user ID:

1
whoami    # This is equivalent to id -un
img

Output the effective user ID

Print Group Names the User Belongs to

We can use group command to display the user’s belonging group names:

1
groups    # This is equivalent to id -Gn
img

Output the user's beloging groups

Or we can specify a user name to view the group to which the user belongs:

1
groups [username]

Print Users Names

We can use users command to display the logged in users’ names:

1
users
img

Output the users' name

Print User Details With finger

We can use finger command to display the user names currently logged in:

1
2
yum install finger -y
finger root
img

Output the details of the specified user

References 20 User information

Buy me a coffeeBuy me a coffee