Skip to content

Identity and groups

Module
Users and Basic Permissions
Difficulty
Easy
Updated
Tested on
Ubuntu 24.04.5 LTS (lab container), GNU Bash 5.2.21
On this page

You created a note, but its metadata names both an owner and a group. Your account also belongs to more than one group. Which identity connects you to that file?

By the end, you can inspect your account, separate its primary group from supplementary groups, and read a practice file’s ownership without changing access.

Finish Practice: Finding Files and Text. Keep your B04 lab directory. Use only disposable ~/lab/b11/identity:

Terminal window
mkdir -p ~/lab/b11/identity
cd ~/lab/b11/identity
printf 'Owner inspection\n' > note.txt

This creates one small text file. If you already used this directory, follow Reset this lesson before repeating the setup. The inspection commands below do not change accounts, groups, or ownership.

Run the shortest identity check first:

Terminal window
whoami
Captured output
learner

whoami prints the name associated with the command’s effective user ID: the identity used for ordinary permission checks. In this session it is learner. Your VM account can have another name. Read what the command reports rather than assuming the prompt’s label establishes identity.

A name is convenient for people. Linux also identifies accounts numerically. Ask for the number and its group context:

Terminal window
id
Captured output
uid=1001(learner) gid=1001(learner) groups=1001(learner),27(sudo)

A UID is a user ID. Here UID 1001 maps to the account name learner. A GID is a group ID. The gid= field identifies the primary group of this shell: group learner, also numbered 1001 in this capture.

The repeated number does not make a user and a group the same object. User IDs and group IDs identify different kinds of identity. An account and its primary group often share a name, but that naming choice is not a requirement.

The groups= list contains the primary group plus supplementary groups, additional group memberships available to the process. Here sudo, numbered 27, is supplementary. There are two groups, not two user accounts. Membership can help determine access to a resource owned by a group.

Predict first: will id -g print every group ID, or only the primary one?

Terminal window
id -g
Run it, then compare with your guess
Captured output
1001

Only the primary group ID. Lowercase -g and uppercase -G ask different questions.

Use -u for the user ID. Add -n to a selected identity field when you want its name instead of its number:

Terminal window
id -u
Captured output
1001
Terminal window
id -gn
Captured output
learner

For the complete group list, use uppercase -G. Combining it with -n prints the names:

Terminal window
id -Gn
Captured output
learner sudo

These are observations of the running session. Changing an account’s configured memberships elsewhere does not automatically replace the group list of every already-running shell. A fresh login is normally needed to start a session with updated memberships. This lesson does not change them.

Inspect the note with B06’s stat. The -c option selects a format: uppercase %U and %G request owner and group names; lowercase %u and %g request their numeric IDs. %n prints the filename.

Terminal window
stat -c '%U %G %u %g %n' note.txt
Captured output
learner learner 1001 1001 note.txt

Read the fields in order: owner name, owning group name, owner UID, owning GID, filename. The file has one owning user and one owning group. It does not contain a list of every group its owner belongs to.

The note belongs to user learner and group learner. Your shell’s supplementary membership in sudo did not make sudo the note’s owning group. Ordinary creation here uses the shell’s primary group; directory group inheritance can change that rule in configurations covered later.

One account, two groups, one owned file Learner has primary group learner and supplementary group sudo. The note is owned by user learner and group learner. learner: UID 1001 Primary: learner (GID 1001) Supplementary: sudo (GID 27) note.txt: learner / learner
One account, two groups, one owned file Learner has primary group learner and supplementary group sudo. The note is owned by user learner and group learner. learner: UID 1001 Primary: learner (GID 1001) Supplementary: sudo (GID 27) note.txt: learner / learner
Simplified model. The learner account has primary group learner and supplementary group sudo; note.txt is owned by learner and group learner.

In words, account identity, group memberships, and file ownership are separate facts. The diagram collects relationships for this account; its lines do not represent commands or a sequence. This model leaves out group-inheriting directories and additional access-control mechanisms.

Read the account, groups, and file ownership
learner@rootvolt:~/lab/b11/identity$ whoamilearnerlearner@rootvolt:~/lab/b11/identity$ iduid=1001(learner) gid=1001(learner) groups=1001(learner),27(sudo)learner@rootvolt:~/lab/b11/identity$ stat -c '%U %G %u %g %n' note.txtlearner learner 1001 1001 note.txtlearner@rootvolt:~/lab/b11/identity$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. Read the current account, its groups, and the note's owning user and group without changing them.
Steps (9)
  1. Type whoami
  2. Press Enter
  3. Output: learner
  4. Type id
  5. Press Enter
  6. Output: uid=1001(learner) gid=1001(learner) groups=1001(learner),27(sudo)
  7. Type stat -c '%U %G %u %g %n' note.txt
  8. Press Enter
  9. Output: learner learner 1001 1001 note.txt

Ownership alone does not tell you whether a particular operation succeeds. The next lesson reads the permission bits that accompany those identities.

Supplying a username to whoami. It reports the current effective identity and does not accept an account argument:

Terminal window
whoami learner
Captured output
whoami: extra operand ‘learner’
Try 'whoami --help' for more information.

Use whoami alone for this session. id can inspect a named account, but a mistyped or absent account has its own diagnostic:

Terminal window
id no-such-b11-account
Captured output
id: ‘no-such-b11-account’: no such user

This says the account lookup failed. It does not say the current shell lost its identity. Check the spelling before assuming an account exists.

Treating sudo membership as an elevated shell. The captured whoami still says learner. A group can be relevant to delegated administration policy without making every command run as root.

Goal: Report your effective account name and every group ID numerically. Explain which numeric group is primary by comparing with the earlier result. Do not change membership.

Hint

Add the name option to the user selection. Use the uppercase group-selection option without the name option for numeric groups.

Solution
Terminal window
id -un
Captured output
learner
Terminal window
id -G
Captured output
1001 27

The primary group is 1001 in this lab capture; 27 is supplementary. Your account’s numbers can differ. Explain the roles from the fields and options, not from memorizing these particular values.

Terminal window
cd ~/lab/b11
ls -AR identity
Terminal window
rm -r ~/lab/b11/identity

Rerun Before you start. If the directory is absent, skip removal. The capture verifies this removal and recreation.

  • whoami names the effective user; id reports numeric identities and groups.
  • A primary group and supplementary groups belong to the running session’s identity.
  • Files have an owning user and an owning group, separate from the owner’s membership list.
  • Inspection reports these facts without granting privileges or changing access.

Next, Reading permission strings connects identities to the access bits in a long listing.