Skip to main content

2.f. verifying user access level

id & groups Verifying user access levels.

What You Will Learn

  1. Understand the role of **user IDs (UIDs) and **group IDs (GIDs) in Linux.
  2. Learn how to check which groups a user belongs to.
  3. Use id, groups, and related commands to verify access levels.
  4. Diagnose permission issues by comparing UID/GID against file ownership.
  5. Apply verification to **WordPress folder ownership (/var/www).
  6. Distinguish between **primary group and supplementary groups.
  7. Interpret id output to troubleshoot permission denied errors.
  8. Implement best practices for group management in WordPress VPS.

Prerequisites

  • **Access Level: Normal user account; sudo for checking other users.
  • **Software: Pre-installed Linux tools (id, groups, whoami).
  • **Knowledge: Basic Linux permissions (ls -l), ownership concepts.

5W + 1H Framework

QuestionAnswer
Whatid, groups, whoami → commands to view user and group information.
WhyTo confirm whether a user has the right permissions for WordPress folders/files.
WhenBefore granting permissions, after user creation, during troubleshooting.
Where/etc/passwd, /etc/group, and runtime environment of /var/www.
WhoAdmins, developers, DevOps working with multi-user WordPress VPS.
HowBy running id USER, groups USER, whoami, and comparing with file ownership.

Core Commands Reference

CommandPurposeExampleExpected Output
idShow UID, GID, and group membershipsiduid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),27(sudo),33(www-data)
id USERNAMECheck details for another userid www-datauid=33(www-data) gid=33(www-data) groups=33(www-data)
groupsList groups current user belongs togroupsubuntu : ubuntu sudo www-data
groups USERNAMEList groups for another usergroups ubuntuubuntu : ubuntu sudo www-data
whoamiShow current effective usernamewhoamiubuntu
getent passwd USERNAMEGet account entry from /etc/passwdgetent passwd www-datawww-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
getent group GROUPNAMEGet group entry from /etc/groupgetent group www-datawww-data:x:33:ubuntu

Understanding UID and GID

  • **UID (User ID): Unique number identifying a user.
  • Example: uid=1000(ubuntu)
  • **GID (Group ID): Primary group associated with the user.
  • Example: gid=1000(ubuntu)
  • **Supplementary Groups: Additional groups granting extra rights.
  • Example: groups=1000(ubuntu),27(sudo),33(www-data)

WordPress Example:

If wp-content/uploads/ is owned by www-data:www-data, the PHP process (www-data) needs to appear in the id or groups output for uploads to work.

Practical WordPress Use Cases

ScenarioCommandExpected Outcome
Check if ubuntu user can manage uploadsgroups ubuntuShould include www-data if ACL/group access configured.
Verify PHP-FPM user identity`ps auxgrep php-fpm→ thenid USER`
Debug file ownership errorls -l wp-content/uploads/ + idCompare owner/group of files vs your groups.
Audit all WordPress users/groups`getent passwdgrep -E "ubuntu

Command Examples with Expected Outputs

Check Current User

whoami

Output:

ubuntu

Check UID, GID, and Groups

id

Output:

uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),27(sudo),33(www-data)

Check Groups for Specific User

groups www-data

Output:

www-data : www-data

Get Detailed Entry

getent passwd www-data

Output:

www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin

Verify Group Membership

getent group www-data

Output:

www-data:x:33:ubuntu

Meaning: ubuntu belongs to www-data group.

Benefits for WordPress Management

ActionBenefit
id / groupsConfirms user belongs to web server group (www-data).
whoamiPrevents accidental root vs normal user operations.
getentVerifies system-level user and group database entries.
Comparing with ls -lDirect mapping between file ownership and user access.

Implementation Steps

  1. Check your identity:

    whoami

  2. Verify your UID, GID, and groups:

    id

  3. Confirm youre in www-data (or PHP user group):

    groups

  4. Audit WordPress ownership vs groups:

    ls -ld /var/www/html/wp-content/uploads/
    id

  5. If missing access, add user to group:

    sudo usermod -aG www-data ubuntu

Troubleshooting Matrix

SymptomLikely CauseFix
“Permission denied” when uploadingUser not in www-data groupsudo usermod -aG www-data <user> then re-login
Files owned by rootCommands run as sudo created filessudo chown -R www-data:www-data /var/www/html
Web server cannot write to uploadsPHP-FPM user not in groupCheck id www-data and adjust ACLs or ownership
Group changes not appliedUser session not refreshedRe-login or newgrp www-data

Quick Lab

# 1. Check current user
whoami

# 2. View groups
groups

# 3. Inspect uploads ownership
ls -ld /var/www/html/wp-content/uploads/

# 4. Verify web server identity
id www-data

# 5. Add your user to web server group (if missing)
sudo usermod -aG www-data ubuntu

Expected Results:

  • You confirm your username (whoami).
  • Groups include www-data.
  • Uploads directory shows www-data ownership.

Cheat Sheet

CommandPurpose
whoamiShow current username
idShow UID, GID, groups
id USERShow another user’s details
groupsList current user’s groups
groups USERList another user’s groups
getent passwd USERView user entry
getent group GROUPView group entry
usermod -aG group userAdd user to group

Mini Quiz

  1. What does id show that groups doesnt?
  2. Why is being part of www-data group important for WordPress admins?
  3. Which command verifies the primary group of a user?
  4. What must you do after usermod -aG to apply group changes?
  5. How would you check if ubuntu is part of www-data group?