โฌ†๏ธ Top

Linux Beginner Series โ€ข Module 4

Users & Groups
Identity, Power & Teams

Learn how Linux knows who you are, what you can access, when you need admin power, and how users join teams like devops. Think of it as a secure office building with ID cards, departments, and one very dangerous master key. ๐Ÿ”

terminal: identity check
student@linux-vm:~$ 
๐Ÿชช

Linux ID Card

Every logged-in account has numeric IDs behind the friendly names.

Userstudent
UID1000
Groupsstudent, sudo
PowerNormal user + sudo approval
Big Idea

Linux is a secure office building ๐Ÿข

Beginners often think users and groups are just names. In Linux, they are the base of permissions. Linux asks three questions again and again: Who are you? Which team are you in? Are you allowed to do this?

๐Ÿ”‘ ๐Ÿชช Linux System
๐Ÿง‘โ€๐Ÿ’ป
User
An employee who logs in and works in the system.
๐Ÿชช
UID
The employee ID number Linux actually trusts.
๐Ÿ‘ฅ
Group / GID
A department/team and its numeric department ID.
๐Ÿ”‘
root / sudo
Master key or temporary manager approval for admin work.
Concepts

Users, groups, UID and GID

Linux displays friendly names like student and devops, but internally it tracks numeric IDs. Names are for humans. Numbers are for the operating system.

๐Ÿ‘ค

Users

A user is an account that can own files, run commands, and log in if allowed.

๐Ÿ‘ฅ

Groups

A group is a team of users. Permissions can be given to a whole group.

#๏ธโƒฃ

UID

User ID. Example: the first normal user is commonly UID 1000 on Ubuntu.

๐Ÿท๏ธ

GID

Group ID. Every group has a number, just like every user has a UID.

ConceptBeginner meaningCommand to inspect
Current userThe account you are using right now.whoami
UID/GID/groupsYour numeric identity and team memberships.id
User databaseLocal account records.getent passwd username
Group databaseLocal group records and members.getent group groupname
โœ… Practical rule

When troubleshooting permissions, first run whoami, then id. Those two commands usually explain half the mystery.

Power Tools

root, sudo and su

root is the super administrator. sudo runs one command with admin rights. su switches identity to another user. Useful? Yes. Dangerous? Also yes. Handle like a sharp knife, not a spoon. ๐Ÿ”ช

๐Ÿ‘‘

root user

UID 0. Can change system files, create users, install packages, and break things very efficiently.

๐Ÿ›‚

sudo

Temporary admin approval for a command, for example sudo useradd testuser.

๐ŸŽญ

su

Switch user. Example: su - testuser starts a login shell as testuser.

Featuresudosu
MeaningRun a command with elevated rights.Switch to another user account.
Common examplesudo useradd testusersu - testuser
Password usedUsually your own password, if you are allowed to sudo.Usually the target user's password.
Beginner memory lineBorrow power for one task.Become someone else.
โš ๏ธ Root caution

Do not practise destructive commands as root on a real system. A wrong root command can remove users, damage files, or change permissions across the system.

Interactive

UID/GID identity simulator

Click an identity. Watch how the same concept appears as human-friendly names and numeric IDs.

๐Ÿง‘โ€๐ŸŽ“

student

Normal learner account

TypeUser account
UID1000
Primary GID1000(student)
Groupsstudent, sudo
Commandid
Linux Files

Decode /etc/passwd and /etc/group ๐Ÿ”

These files look scary only because they are compact. Once decoded, they are just structured records.

Example passwd entry

testuser:x:1001:1001::/home/testuser:/bin/sh
Username: the human-friendly account name used to log in or own files.
Safer inspection command
getent passwd testuser

getent asks the system account database. This works better than assuming everything comes only from local files.

Example group entry

devops:x:1002:testuser
Group name: the friendly name of the team or department.
Safer inspection command
getent group devops

This should show the group name, placeholder, GID, and listed members.

Command Superpowers

Command cards โšก

Each command has a job. Learn the job first; memorization becomes much easier.

๐Ÿชž whoami

Shows your current username.

whoami
student
๐Ÿชช id

Shows UID, primary GID, and group memberships.

id
uid=1000(student) gid=1000(student) groups=1000(student),27(sudo)
๐Ÿ‘ค useradd

Creates a new user account.

sudo useradd testuser
No output usually means success.
๐Ÿ” passwd

Sets or changes a user's password.

sudo passwd testuser
New password:
Retype new password:
passwd: password updated successfully
๐Ÿ‘ฅ groupadd

Creates a new group.

sudo groupadd devops
No output usually means success.
โž• usermod -aG

Adds a user to a supplementary group without removing existing groups.

sudo usermod -aG devops testuser
No output usually means success.
Verify with: id testuser
Guided Hands-on

Lab: Create a user and add them to devops

Run these commands on your Linux VM. Use a lab VM, not a production machine. The expected UID/GID numbers may differ on your system; the names should match.

1

Check who you are

whoami

Expected: your current login name, such as student or jp.

2

Check your UID, GID and groups

id

Look for uid=, gid=, and groups=. If you see sudo, your user can likely run admin commands.

3

Create the lab user

sudo useradd testuser

Expected: usually no output. Silence in Linux often means success. Very dramatic, very Linux.

4

Set password for testuser

sudo passwd testuser

Expected: password prompts. Typed passwords will not appear on screen; that is normal.

5

Create the devops group

sudo groupadd devops

Expected: usually no output. If it says group already exists, continue with verification or choose another group name.

6

Add testuser to devops

sudo usermod -aG devops testuser

Important: use -aG, not just -G. -a means append.

7

Verify the result

id testuser
uid=1001(testuser) gid=1001(testuser) groups=1001(testuser),1002(devops)

Victory condition: devops appears in the groups list.

Optional: inspect account and group databases
getent passwd testuser getent group devops

These commands verify the records without manually opening system files.

Troubleshooting

Common beginner mistakes ๐Ÿ˜…

โš ๏ธ Mistake: using -G without -a

Bad: sudo usermod -G devops testuser

Better: sudo usermod -aG devops testuser

-aG appends. Without -a, existing supplementary groups may be replaced.

โณ Mistake: expecting group changes instantly

For the modified user, group membership may require a new login session to fully apply.

Verification command: id testuser. For your own user, log out and log in again.

๐Ÿ”‡ Mistake: thinking no output means failure

Many Linux admin commands print nothing when successful.

Verify instead of guessing: getent passwd testuser and getent group devops.

๐Ÿ‘‘ Mistake: staying root too long

Use sudo for specific tasks instead of living inside a root shell unless you truly need it.

Less time with the master key = fewer accidental disasters.

Final Mission

Boss Battle: Create the DevOps teammate ๐ŸŽฎ

Your mission: create testuser, create devops, attach the user to that team, and prove it with id testuser.

Mission checklist

๐Ÿ† Mission complete! testuser has joined the devops guild.
Reset Lab

Cleanup commands ๐Ÿงน

Use these only in your lab VM when you want to remove the practice user and group.

Remove testuser
sudo userdel -r testuser

-r removes the user's home directory and mail spool where applicable.

Remove devops group
sudo groupdel devops

If the group is still a primary group for a user, Linux may refuse to delete it.

Knowledge Check

Quick quiz ๐ŸŽฏ

Click an answer and get instant feedback. No exam pressure โ€” just tiny brain push-ups.

Print-friendly

Cheat sheet ๐Ÿงพ

Keep this section handy while teaching or practising.

whoamiShow current username.
idShow current UID, GID, and groups.
id testuserShow identity details of testuser.
sudo useradd testuserCreate a new user.
sudo passwd testuserSet password for testuser.
sudo groupadd devopsCreate a new group.
sudo usermod -aG devops testuserAdd testuser to devops safely.
getent passwd testuserCheck testuser in account database.
getent group devopsCheck devops group and members.
su - testuserSwitch to testuser login shell.
sudo userdel -r testuserRemove lab user and home directory.
sudo groupdel devopsRemove lab group.