Software & Apps Linux Using the Linux "id" Command Share Pin Email Print Linux Switching from Windows By Gary Newell Writer Gary Newell was a freelance contributor, application developer, and software tester with 20+ years in IT, working on Linux, UNIX, and Windows. our editorial process Gary Newell Updated May 22, 2019 This guide will show you how to print out information about the current user including the groups they belong to. If you want to show system information you can use the uname command. id (Display Complete User Information) On its own the id command prints a lot of information: user IDusernamegroup IDgroup nameID of other groupsnames of other groups You can run the id command as follows: id The id command will reveal all the information about the current user but you can also specify the name of another user. For example: id fred id -g (Display Primary Group ID for a User) If you want to find the primary group id for the current user type the following command: id -g This will list just the group id such as 1001. You might be wondering what a primary group is. When you create a user, for example, fred, they are assigned a group based on the settings of the /etc/passwd file. When that user creates files they will be owned by fred and assigned to the primary group. If other users are given access to the group they will have the same permissions as other users within that group. You can also use the following syntax for viewing the primary group id: id --group If you want to see the primary group id for a different user specify the user's name: id -g fred id -G (Display Secondary Group ID for a User) If you want to find the secondary groups a user belongs to type the following command: id -G The output from the above command will be along the lines of 1000 4 27 38 46 187. As mentioned previously a user is assigned to a single primary group but they can also be added to secondary groups. For example, fred might have a primary group of 1001 but he might also belong to groups 2000 (accounts), 3000 (managers) etc. You can also use the following syntax for viewing the secondary group ids. id --groups If you want to see the secondary group id for a different user specify the user's name: id -G fred id -gn (Display Primary Group Name For A User) Displaying the group id is fine but as human beings, it is much easier to understand things when they are named. The following command shows the name of the primary group for a user: id -gn The output for this command on a standard Linux distribution is likely to be the same as the username. For example, fred. You can also use the following syntax for viewing the group name: id --group --name If you want to see the primary group name for another user include the user's name in the command: id -gn fred id -Gn (Display Secondary Group Name for a User) If you want to display the secondary group names and not the id numbers for a user enter the following command: id -Gn The output will be something along the lines of fred adm cdrom sudo sambashare. You can get the same information by using the following syntax: id --groups --name If you want to see the secondary group names for another user specify the user's name in the command: id -Gn fred id -u (Display User ID) If you want to display the user id for the current user type in the following command: id -u The output from the command will be something along the lines of 1000. You can achieve the same effect by typing the following command: id --user You can find out the user id for another user by specifying the user's name as part of the command: id -u fred id -un (Display User Name) You can display the username for the current user by typing the following command: id -un The output from the above command will be something along the lines of fred. You can also use the following command to display the same information: id --user --name There is little point in supplying another user's name to this command. Summary The main reason to use the id command is to find out what groups a user belongs to and sometimes to find out which user you are logged in as especially if you use the su command to switch between users. In the latter case, you can use the whoami command to find out who you are logged in as and you can use the groups command to find out which groups a user belongs to. The su command should only be used if you need to run a number of commands as a different user. For ad-hoc commands you should use the sudo command.