id Command Guide for Checking Your User and Group Identities
id prints who you are — your user ID, your groups, and their IDs — the identity the kernel actually uses for permission checks.
What is id, and Why Use It?
Every process on Linux runs as a user and a set of groups, identified by numbers, not names. id shows you exactly those numbers and names for the current user — or for any user you name. It’s the fastest way to answer “who am I, really?” when permissions decide whether something works or fails with “Permission denied”.
When you run id with no arguments, it shows your own identity:
id
uid=1000(alice) gid=1000(alice) groups=1000(alice),27(sudo),44(video)
Why Learn id?
- Permissions are enforced by UID and GID numbers — names are just labels;
idshows the numbers that actually matter. - It explains group membership — which groups you belong to determines what you can read, write, and execute.
- It’s the first diagnostic for permission errors — before changing anything with
chmod, check who the files and commands belong to. - Scripts and servers rely on it — “is this user in the right group?” is a question
idanswers in one line.
If
chmodandchownare the verbs of permissions,idis the noun: it tells you who you and your files actually are. Check identity first, change permissions second.
1. Show Your Own Identity
id
Example:
$ id
uid=1000(alice) gid=1000(alice) groups=1000(alice),27(sudo),999(docker)
Reading the output:
uid=1000(alice)— your user ID is 1000, and its name is alice.gid=1000(alice)— your primary group is 1000.groups=...— all your supplementary groups: sudo, docker, and so on.
The names in parentheses are looked up from /etc/passwd and /etc/group.
2. Look Up Another User
Name a user to inspect their identity:
id username
Example:
$ id root
uid=0(root) gid=0(root) groups=0(root)
$ id postgres
uid=113(postgres) gid=118(postgres) groups=118(postgres)
$ id www-data
uid=33(www-data) gid=33(www-data) groups=33(www-data)
- Useful when debugging a service: “what user is this running as?”
- The UID tells you privilege level at a glance: 0 is always root.
- If the user doesn’t exist,
idsays so and exits with an error.
3. Show Only the Numbers
Skip name resolution for scripts and raw inspection:
id -u # user ID only
id -g # primary group ID only
id -G # all group IDs
Example:
$ id -u
1000
$ id -g
1000
$ id -G
1000 27 999
$ id -un # username only
alice
id -uis a common test in shell scripts:if [ "$(id -u)" -eq 0 ]; then ...checks “am I root?”- Numeric output is stable even if name lookups fail (e.g., on a machine where
/etc/passwdis unavailable).
4. Check a File’s Ownership in ID Terms
The ls -l output pairs with id to make ownership concrete:
ls -l secret.txt
id -nG
Example:
$ ls -l secret.txt
-rw-r----- 1 alice devs 512 Dec 4 10:00 secret.txt
$ id -nG
alice sudo docker
$ id -gn
alice
- The file belongs to
alice:devs; the permission for group members applies only if you’re indevs. - You’re not in
devs, so the group read bit does nothing for you — which is why the fix ischgrporchown, notchmod.
5. Why UID Zero Is Special
Linux treats UID 0 as root, regardless of the account’s name:
# An account named "notroot" with uid 0 is still fully root
$ id notroot
uid=0(notroot) gid=0(root) groups=0(root)
- Checks like
if [ $(id -u) -eq 0 ]are how scripts detect root. - Some container setups exploit this — a container process can be UID 0 inside while mapping to an unprivileged host user.
- This is also why
chmod 4755(setuid root) binaries are powerful — and why you should audit them carefully.
Common Pitfalls
- Relying on names when numbers matter. Permission checks use UIDs/GIDs; if
idshows a name you don’t recognize, check the numeric ID against/etc/group. - Forgetting that group membership changes at login. Adding yourself to a group with
usermoddoesn’t apply to running shells — log out and back in, then confirm withid. - Using
idto check file ownership.idshows your identity; for files usels -l(orstat). - Assuming the primary group.
gid=is your primary group, butgroups=is the full list — permission checks consider the full list. - Running
idinside a container and expecting host answers. A container has its own users and groups;idshows the container’s view, which may differ from the host’s.
Related Pages
| Page | Why it’s related |
|---|---|
| whoami | The shorter “what’s my username?” check |
| chmod | Permission bits only make sense once you know who you are |
| chown | Changing ownership, verified with id |
| chgrp | Joining a file’s group — or finding out you haven’t |
| /etc/passwd | Where id gets the names for its numbers |
| sudo | Running as root when your id says you’re not |
id Cheatsheet
| Command | Meaning |
|---|---|
id | Show your full identity (user + groups) |
id username | Show another user’s identity |
id -u | Print only your numeric user ID |
id -g | Print only your primary group ID |
id -G | Print all your group IDs |
id -un | Print only your username |
id -gn | Print only your primary group name |
id -nG | Print all your group names |
[ $(id -u) -eq 0 ] | The classic “am I root?” shell test |