0
0
Linux CLIscripting~3 mins

whoami and id commands in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to know which user you are logged in as or details about your user account. The whoami and id commands help you find out your current username and user identity information quickly.
When you want to confirm which user account you are currently using in a terminal session.
When you need to check your user ID (UID) and group ID (GID) for permissions troubleshooting.
When you want to see all groups your user belongs to for access control checks.
When running scripts that behave differently based on the current user identity.
When you want to verify if you have root or administrative privileges.
Commands
This command shows your current logged-in username. It is a quick way to confirm which user you are operating as.
Terminal
whoami
Expected OutputExpected
exampleuser
This command displays your user ID (UID), primary group ID (GID), and all groups you belong to. It helps understand your permissions and group memberships.
Terminal
id
Expected OutputExpected
uid=1000(exampleuser) gid=1000(exampleuser) groups=1000(exampleuser),27(sudo),1001(developers)
-u - Show only the user ID (UID).
-g - Show only the primary group ID (GID).
-G - Show all group IDs the user belongs to.
This command shows only your numeric user ID (UID). Useful for scripts or checks that need just the UID.
Terminal
id -u
Expected OutputExpected
1000
-u - Show only the user ID (UID).
Key Concept

If you remember nothing else, remember: whoami tells your username, and id gives detailed user and group identity info.

Common Mistakes
Using whoami to get group information.
whoami only shows the username, not groups or IDs.
Use the id command to see groups and user IDs.
Expecting id to show the username only.
id shows numeric IDs and group memberships, not just the username.
Use whoami for username, id for detailed identity info.
Summary
Use whoami to quickly see your current username.
Use id to get your user ID, primary group ID, and all group memberships.
Flags like -u, -g, and -G with id help show specific identity details.