Linux Foundations / Understand Identity and Access

Inspect users, groups and ownership

Lesson 17 of 37. Open to read. No account needed.

An unfamiliar group name is a reason to inspect evidence, not immediately to change an account. The identity of the process running a command, an account database record, and a file's owner/group metadata answer related but different questions. None of those observations alone proves that a particular file operation is permitted.

You will compare your ordinary guest identity with two owned notes, resolve one observed group through the configured account database, and inspect the owner of one named system entry. No user, group, authentication or privilege setting is changed.

1. Establish the current execution identity

Complete Build a small report from supplied records first. Use the checked Ubuntu guest's ordinary Bash account. Run each command one line at a time, read its result, and stop on unexpected errors before continuing. Use the earlier checks first:

id -u
id -un
ps -p $ -o comm=
type printf mkdir id whoami stat getent cat ls rm rmdir

Require your expected nonzero user ID, ordinary username and Bash. printf should be a Bash builtin; the utilities must resolve to their expected guest executables. Preserve an understood color-only listing alias and reconcile other unexpected aliases, functions or origins before use. Do not continue this exercise as root or through a different execution identity.

Effective user, primary group and additional groups

whoami prints the name associated with the process's effective user ID. For this purpose it is equivalent to the taught id -un. It does not simply print a USER environment value or identify whoever originally logged in before a different execution context was selected.

Argumentless id reports the current process identity and groups. In an ordinary session it shows user and group identifiers with resolved names, plus the group list. If real and effective identities differ, additional identity fields can appear. That is an unexpected context for this task: stop and reconcile it rather than assuming the ordinary example applies.

Inspect these complementary views:

whoami
id

An illustrative ordinary result could contain uid=1000(mira), gid=1000(mira) and a groups= list. Your actual IDs, names and group count may differ. Record your own observations; do not type illustrative IDs into later queries.

The primary group is one group associated with the process. Supplementary groups are additional group identities carried by it. The displayed group list is not a list of supplementary groups only; it also includes primary group information. Inspect the numeric forms before comparing them to files:

  • id -g prints the effective primary group ID.
  • id -G prints all current group IDs.
  • id -Gn asks for those group IDs represented as names; -n selects names with the group-list query.
id -g
id -G
id -Gn

Record the primary numeric ID and the complete current group-ID set. Keep the names beside the IDs as readable labels. Do not assume a group name must equal the username, or call the whole id -G output supplementary membership.

2. Ask one database question without replacing process evidence

getent reads a named database through the system's configured Name Service Switch, or NSS. That configuration can consult local records or other configured sources. A getent group KEY query asks for one group entry: a numeric key selects a group ID; a nonnumeric name selects a group name. Always supply the specific key here; do not enumerate the whole group database.

We will use the primary group ID you just observed. First confirm that the standalone id -g command succeeded and printed that expected single numeric ID. The shell syntax $(...) is command substitution: Bash runs the command inside, removes its trailing newline, and substitutes the resulting text. Double quotes around the substitution keep that result as one argument.

In this exact expression, the enclosed command is the already explained, read-only id -g. No account name, guessed ID or file write is hidden inside:

getent group "$(id -g)"

The numeric key comes from the current process's effective primary group. This query is read-only. A normal result has four colon-separated fields:

FieldMeaning
1Group name resolved by the configured database.
2Group password field, commonly a placeholder such as x; it is not a login instruction.
3Numeric group ID. Compare it with the observed id -g result.
4Comma-separated listed member names; it can be empty.

An illustrative entry is mira:x:1000:. The empty final field does not prove that the current user lacks that primary group. Primary membership is represented through account/group-ID relationships rather than necessarily being repeated in this listed-member field. Nor does this record establish the complete current supplementary group set: the current process's id evidence is the relevant observation for that question.

If no entry is returned or a diagnostic appears, inspect the immediate status with the already taught $? pattern and recheck the actual numeric key and configured setup. Do not invent a group name, create a replacement group or change membership to suppress an unfamiliar result.

Current process versus a named account query

Adding a user operand to id changes the question to identity information for that named account, obtained through the configured account sources. It does not recreate the credentials of your already running shell. The two can differ, for example after account membership changes that an existing session has not adopted.

Use the same explained command substitution to supply the effective username from whoami as one quoted operand:

id "$(whoami)"

Compare it with the earlier argumentless id. Agreement is unsurprising in the ordinary unchanged guest, but do not replace current-process evidence with this named-account query. A differing result calls for identifying the context and database distinction, not modifying groups during this lesson.

3. Create two owned notes for metadata comparison

This file task owns ~/linux-practice/inspect-users-and-groups/. Inspect its parents and prospective name without trailing slashes:

ls -ld ~
ls -ld ~/linux-practice
ls -ld ~/linux-practice/inspect-users-and-groups

Require ordinary parent directories owned by the expected user, with no links or unrecognized identity. The exercise name must be absent for a fresh start; use the resume section if it already exists. Only after that check:

mkdir ~/linux-practice/inspect-users-and-groups
ls -ld ~/linux-practice/inspect-users-and-groups

Require the expected ordinary directory and owner, then enter separately:

cd ~/linux-practice/inspect-users-and-groups
pwd
ls -a

Require the recorded shared-root path followed by /inspect-users-and-groups and only . and ... The taught printf and redirection now create two new synthetic inputs; each name must be absent before its first write:

printf '%s\n' 'Identity inspection note' > identity-note.txt
printf '%s\n' 'Handoff comparison note' > handoff-note.txt

Inspect both files and their complete contents:

ls -ld -- identity-note.txt handoff-note.txt
cat identity-note.txt
cat handoff-note.txt

Require ordinary regular files, shown with leading -, one link each and the expected owner. The saved lines must match the supplied text. Keep both notes unchanged until the independent comparisons are complete.

4. Pair numeric ownership with resolved names

stat reports metadata about a named filesystem entry. For the file inspection form here, -c selects a format string. Stat interprets the percent codes in that single quoted argument and appends a newline to each formatted result. The following codes belong to this file format:

CodeReported field
%nSupplied filename.
%FEntry type.
%u and %UNumeric owner user ID and resolved owner name.
%g and %GNumeric owning group ID and resolved group name.
%hNumber of hard links.

The words, spaces, equals signs and parentheses in the format are literal labels to make the observation readable. -- ends option parsing before the named operand. Predict which numeric field should match your effective user ID for the note you just created:

stat -c 'path=%n type=%F owner=%u(%U) group=%g(%G) links=%h' -- identity-note.txt

Require the known regular file and one link. Its numeric owner should match the ordinary identity that created it. Compare names as resolved labels, but retain the numeric IDs so different or missing name resolution remains visible.

Observe the file's group independently. A newly created file's group can be influenced by its containing directory and inheritance rules; do not calculate it from the username or assume it must equal the primary group. Record the actual numeric group and see whether it appears in the current id -G set. More detailed permission and directory behavior is taught in the next lesson.

Inspect one system entry without changing it

The same read-only metadata command can inspect the named system entry /etc/os-release without editing its contents:

stat -c 'path=%n type=%F owner=%u(%U) group=%g(%G) links=%h' -- /etc/os-release

Record the actual type, numeric owner and group. This path may be a symbolic link. By default, this stat invocation reports the named link itself rather than dereferencing it; do not label that metadata as the target's ownership. No assumption about its precise type or IDs is needed for the comparison.

A different owner explains whose ownership metadata you observed. It does not, by itself, establish whether your user can read, edit or remove the object. Do not try to change ownership or edit the system entry to test the distinction.

5. Ownership evidence is not the complete access decision

Identity tells you which user/group credentials the current process carries. File metadata tells you which user and group own the named object. To decide whether a particular operation is permitted, you also need the applicable permissions and the directory path involved. The next lesson teaches the ordinary owner/group/other class rules and file-versus-directory permissions.

For a normally writable note in this owned practice setup, use your ordinary account for the taught edit. Ownership alone is not a guarantee of write permission, so an unexpected denial calls for inspection, not automatic use of sudo. Creating a new lab account is a different kind of operation that may require specifically authorized guest administration in a later lesson.

sudo runs an allowed command under a delegated identity according to the system's policy; it is not a general repair for an unfamiliar group or file error. No sudo invocation, account creation or group change is needed for the read-only identity queries and this ordinary owned-note fixture.

Diagnose which evidence differs

ObservationWhat to distinguishSafe next check
whoami is not the expected guest user.Effective execution identity versus an assumed login name.Stop and reconcile the shell context before creating or editing notes.
Argumentless id and id USER differ.Current process credentials versus named-account database information.Record both questions and investigate the session/setup; do not change membership here.
A group entry has an empty member field.Listed database members versus primary/current process membership.Compare its numeric GID with id -g and the full current group-ID set.
File group and username differ.User names and group ownership are different properties.Inspect the numeric file GID and resolve an observed group key rather than renaming it.
A numeric ID is present but its name is unfamiliar or unresolved.Stored ownership identifier versus name-service resolution.Preserve the number and inspect the configured lookup result; do not invent a replacement name.
Owner or group matches, but an operation is denied.Identity/ownership alone does not establish effective access.Inspect the actual operation and path with the permission model taught next, rather than elevating privilege automatically.

Independent task: map both notes to the current process

Keep the same ordinary guest context and exact exercise path. Recheck the two notes' identities and supplied content. Without opening the answer:

  1. Record the current effective username/UID, primary GID and complete group-ID set. Distinguish the primary group from additional groups.
  2. Inspect both notes with the taught formatted stat and record each numeric owner/group beside its resolved name.
  3. For each note, state whether its owner ID matches the current effective UID and whether its group ID appears in the current process's group set. If it matches the primary GID, say so; otherwise do not call it primary merely because the process carries it.
  4. Explain why these comparisons alone cannot establish which read, write or execute operations are allowed. Explain why the listed members from a getent group record are not a complete replacement for current id output.
  5. Explain the privilege difference between editing a normally writable owned note and creating a new lab account. Perform no privilege or account change.

Both files may legitimately have the same owner and group; the task does not require altering one to manufacture a difference. Success is an accurate mapping from actual identifiers, unchanged source text, and a clear statement of what the available evidence does and does not prove.

Graduated hints

  1. Start with the process observations. A familiar username alone is not the full user/group credential set, and the primary group is not the whole list.
  2. Stat's lowercase %u/%g are numeric IDs; uppercase %U/%G are names. Compare numeric IDs first, then use names to explain the observed mapping.
  3. Do not select an access class or infer permission from ownership alone. The current task supplies identities; the next lesson supplies the access rules and path checks needed for that later decision.

Answer and Reasoning

From the verified ordinary context, the process observations are:

whoami
id -u
id
id -g
id -G
id -Gn

Use your actual IDs and names, not the illustrative 1000 values. Under the ordinary checked context, the effective UID is the one to compare with these newly created notes. Inspect both with the same explicit file format:

stat -c 'path=%n type=%F owner=%u(%U) group=%g(%G) links=%h' -- identity-note.txt handoff-note.txt
cat identity-note.txt
cat handoff-note.txt

Stat prints one labelled result per named file. Both should still be the known regular single-link files with the same supplied text. Their numeric owner IDs should match the creating ordinary user. Record each actual owning group; do not substitute the username or assume a particular numeric value.

For each file, compare its %g number with id -g and with the complete id -G set. A primary-GID match and a match to an additional group are related but different observations. If the file group is not in that set, record the absence; it is not permission to add the user to that group.

The named getent query resolves a database entry for an observed group ID. Its listed members do not independently enumerate every account using that primary group or every credential held by this running process. Likewise, id "$(whoami)" asks about the named account; it cannot replace the current process observation if the session and database have diverged.

None of these matches supplies the object's permission bits, the applicable class decision or every parent-directory requirement. The correct conclusion is an ownership/membership mapping, not a blanket claim of access. Use the ordinary account for an allowed owned-file edit. Account administration is a separately authorized later task, not a reason to invoke sudo during this one.

Cleanup after both-file comparisons

Finish the independent evidence before removing the notes. Inspect the shared root and exercise entries without trailing slashes:

ls -ld ~/linux-practice
ls -ld ~/linux-practice/inspect-users-and-groups

Require the recognized ordinary owned directories. Enter and verify separately:

cd ~/linux-practice/inspect-users-and-groups
pwd

Require the exact recorded exercise path before inspecting the two targets:

ls -a
ls -ld -- identity-note.txt handoff-note.txt

Require only the two recognized regular single-link files owned by the recorded user, plus dot entries. Recheck contents if necessary; leave an unrecognized entry untouched. The shown y/n responses assume English confirmations. Establish the actual documented response convention before removal, and stop if it is unclear. Only after these checks:

rm -i -- identity-note.txt handoff-note.txt

Approve only the known notes. To stop approval, decline the current and every remaining prompt; one refusal does not cancel later prompts. Inspect ls -a and require only . and .. before directory removal.

Return to the shared root and verify it first:

cd ~/linux-practice
pwd

Require the recorded shared-root path, then inspect the exercise entry:

ls -ld -- inspect-users-and-groups

Only for the recognized owned empty directory:

rmdir -- inspect-users-and-groups
ls -a

Retain the shared root and other lessons. No account or group was created, so there is no identity record to delete or membership to restore.

Resume from observed context

After interruption, recheck the effective identity, current process groups, command origins, directory identities and exact location. Inspect both notes and their contents before resuming. An unexpected user or changed group set is context to investigate, not a reason to change ownership automatically.

Do not rerun the starter writes over existing notes. For a recognized partial fixture, create only a verified missing named note with its supplied text. Preserve unknown entries. For a complete restart, remove only the recognized owned notes and empty exercise directory using the same guarded procedure, then rebuild a fresh fixture. Leave account databases and the named system entry unchanged.

Sources and other study views

The course uses Ubuntu Noble's declared tool families. Rolling Coreutils material and the older Debian sudo companion support the bounded distinctions here without making every newer or different-platform feature part of the task.

Revision reconstructs the evidence distinctions; Quick Reference retrieves the named inspections after study.

Study this course with an account

Course access adds revision notes, the Quick Reference, saved progress, bookmarks and your own notes.

INR 99 plus 18% GST. 90 days of online access. No auto-renewal.

See course access

This website is operated by VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED, operating as Vectametric.

Corporate Identity Number (CIN): U85499KA2026OPC229822. GSTIN: 29AAMCV8281D1ZS. Registered office: RS NO/38/2A/1 BASTAND, ROAD MAHANTESH NAGAR, Ramdurg, Ramdurg, Belgaum- 591123, Karnataka.

Queries and grievances: Prajval Honnungar, Grievance Officer and Data Protection Contact.

Telephone: +91 94800 09310. Support: support@vectametric.com. Grievances: support@vectametric.com.

Copyright 2026 VECTAMETRIC EDTECH (OPC) PRIVATE LIMITED. All rights reserved.

Vectametric home · Roadmaps · Vecta IT Exams · Vecta Government Exams · Vecta Banking & Finance Exams · Vecta Entrance Exams · About us · Contact · Privacy Policy · Terms and Conditions · No-Refund Policy