Using the 'id' Command
The id
command is a powerful tool that provides detailed information about a user, including their group membership. Unlike the groups
command, which only lists the groups a user belongs to, the id
command offers a more comprehensive view of the user's identity and permissions.
To use the id
command, simply run it with the username as an argument:
id username
This will display the following information:
- User ID (UID)
- Primary group ID (GID)
- Primary group name
- All the secondary groups the user belongs to
Here's an example output on an Ubuntu 22.04 system:
$ id user1
uid=1000(user1) gid=1000(user1) groups=1000(user1),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),113(lxd),128(lpadmin),129(sambashare)
In this example, the user user1
has a UID of 1000 and a primary group of user1
(GID 1000). The user is also a member of several secondary groups, such as adm
, sudo
, and lxd
.
If you don't specify a username, the id
command will display information about the current user:
id
This can be useful when you need to quickly check your own user and group information.
By using the id
command, you can gain a comprehensive understanding of a user's identity and group membership in your Linux system. This information is crucial for managing user permissions and access control.