- Learn
- Computer Science & IT
- Information Technology
- Linux Basics
- Linux Users, Groups and Permissions
Linux Users, Groups and Permissions
sudo. Create and manage users and groups, read and change ownership and permissions with chown and chmod, set sensible defaults with umask, and use the SUID, SGID and sticky bits. Finish by tracing a "Permission denied" error to its cause and fixing it with the smallest safe change.BeginnerLesson 5 of 7 in Linux Basics Course
What you will learn
- Explain how Linux identifies every user and group by number, tell root, regular and system accounts apart, and read the files that store accounts, groups and password data.
- Tell root, regular and system accounts apartDescribe the three kinds of accounts, the user ID that identifies each one, and the commands that show who you are and who is logged in.
- Explain primary and supplementary groupsExplain how groups give several users the same access, the difference between a user's primary group and supplementary groups, and which groups carry special rights.
- Read the passwd, shadow and group filesRead every field of /etc/passwd, /etc/shadow and /etc/group, explain why password hashes are kept apart, and work out password dates from the shadow file.
- Tell root, regular and system accounts apart
- Work as a regular user, raise privileges with sudo or su only for the commands that need them, and give other users exactly the administrative rights they need.
- Use sudo and su to act as rootCompare su and sudo, run single commands with elevated rights, and avoid the usual sudo pitfalls such as root-owned files and redirection that fails.
- Grant sudo rights with the sudoers policyRead and write sudoers rules with visudo, make a user an administrator through the right group, and limit other users to the few commands they need.
- Use sudo and su to act as root
- Add users and groups from the command line, set and control passwords, change and remove accounts, and manage who belongs to which group.
- Create user accounts with useradd and adduserCreate regular and system accounts with useradd or adduser, know which files and defaults each one uses, and check the result.
- Manage passwords and change or remove accountsSet, lock and expire passwords, apply password aging, change account details with usermod, and remove accounts without leaving problems behind.
- Create groups and manage membershipCreate, rename and delete groups, add and remove members, and set up a folder that a team can share.
- Create user accounts with useradd and adduser
- Read the owner, group and permission bits of any file or directory, explain what each permission allows, and change them with chmod, chown and chgrp.
- Read ownership and permissions in a listingRead every part of an ls -l line and work out which permission class applies to a given user.
- Explain what read, write and execute allowExplain what r, w and x allow on a regular file and on a directory, and predict whether an operation such as reading, running, creating or deleting succeeds.
- Change permissions with chmodSet and change permissions with symbolic and octal modes, convert between the two forms, and change whole directory trees safely.
- Change ownership with chown and chgrpChange the owning user and group of files and directory trees, know who is allowed to do so, and predict who owns newly created, copied and moved files.
- Read ownership and permissions in a listing
- Choose the permissions new files receive, use the SUID, SGID and sticky bits where they help, and trace a permission error to its cause and fix it with the smallest safe change.
- Set default permissions with umaskWork out the permissions of new files and directories from the umask, and set a umask for a session or permanently.
- Use SUID, SGID and the sticky bitExplain the three special permission bits, recognize them in listings, set them with chmod and use them safely for programs, team folders and shared directories.
- Diagnose permission problems and apply least privilegeTrace a "Permission denied" error step by step, choose the smallest safe fix, and keep sensitive files and administrator rights tightly restricted.
- Set default permissions with umask
Linux Users, Groups and Permissions study guide
1Understand users, groups and the account files
Linux assigns an identity to every person and running service. That identity connects a user ID and group memberships to the files the process may access. Reading your current identity, the active login sessions and the account records makes access decisions easier to explain. The public account file describes who an account is, while protected password records control how password login and aging work.
1.1 Tell root, regular and system accounts apart
Every command runs with an identity. Linux uses that identity to decide which files the command may open and which settings it may change. A user account can represent a person or a service running in the background.
The number behind the name
The kernel identifies an account by its user ID (UID). Names such as alice make the number easier to recognize, but permissions follow the number. The root account has UID 0 and its home directory is /root. An account with another name and UID 0 has the same superuser power.
A regular user is a person's everyday account. On most distributions regular UIDs start at 1000; UID_MIN in /etc/login.defs sets that boundary. A regular user can change their own files and any other files the permissions allow. Changing protected system settings needs elevated rights.
A system account gives a service its own limited identity. Most have UIDs below 1000 and a shell such as /usr/sbin/nologin. The special account nobody commonly has UID 65534, so the range alone does not identify every service account. Debian and Ubuntu use www-data for web services; an SSH service may use sshd.
Read your current identity
Run whoami for your user name or id for the numbers and groups. For example:
uid=1001(alice) gid=1001(alice) groups=1001(alice),27(sudo),1005(developers)
Read the output in three parts. Alice's UID is 1001. Her primary group is alice, GID 1001. Her group list also includes sudo and developers. She is a regular user, not root: the sudo group can authorize elevated commands, but her current shell still runs as Alice.
Many shells display # for root and $ for a regular user. A prompt can be customized, so inspect id when the identity matters. The first account created during installation is often a regular account with sudo access, including on Ubuntu; being created first does not make it root.
Check login sessions
| Command | What it shows |
|---|---|
who | Current login sessions, terminals and login times |
w | Current sessions, activity, uptime and load |
last | Recorded past logins and reboots, newest first |
wtmpdb last | Login history on systems using wtmpdb |
These commands answer a different question from whoami: they report sessions, not just the identity of your shell. Debian 13 is one system that uses wtmpdb for its history.
Separate identities support least privilege, accountability and isolation. A web service can read the files it serves without getting every user's private documents. Logs can show which account acted. If the service is compromised, the attack begins with that service account's rights. Root can bypass ordinary file read and write restrictions, so a second UID 0 account is a serious security concern.
Key Takeaways
- Linux tracks user identities by UID; UID 0 has root power.
- Regular accounts serve people; system accounts give services limited identities.
idshows your identity and active groups; membership insudodoes not make your shell root.whoandwshow current sessions;lastorwtmpdb lastshows recorded history.
1.2 Explain primary and supplementary groups
Sharing a file with a team is easier when the team has a group. Assign the file to that group, give the group the needed permissions, and manage membership as people join or leave.
One primary group, extra memberships
A group has a name and a numeric group ID (GID). Each user has one primary group, stored as a GID in /etc/passwd. A new file normally takes the creating process's primary group. Later, an SGID directory will provide another rule for assigning a new file's group.
Users can also have several supplementary groups. Those memberships add group identities to their processes; the user does not need to switch primary groups each time they open a different team's file. Both primary and supplementary groups count when Linux checks whether the user belongs to a file's group.
Most distributions create a user private group alongside each regular user. Alice may have user name alice, UID 1001, primary group alice and GID 1001. These are still separate user and group identities even when their names and numbers match. A file assigned to Alice's private group is not shared with the whole team.
Inspect a membership
Use groups for your own group names. groups bob and id bob query Bob's memberships; id -Gn prints the current process's group names without numbers. A group lookup might show:
getent group developers
developers:x:1005:alice,bob
The group is named developers, its GID is 1005, and Alice and Bob are listed as supplementary members. An account whose primary GID is 1005 belongs to the group too, even if its name is absent from that final list. To check a person's full membership, use id with their name instead of relying on that list alone.
Apply a group's permissions
Suppose plan.txt belongs to bob:developers and has mode rw-r-----. Alice is not Bob, but she belongs to developers. She therefore uses the middle permission triplet, r--: she can read the plan but cannot change its contents. Chen belongs to neither the owning user nor the group, so he uses the final triplet, ---.
Changing the group name attached to a file does not create permissions by itself. If its group triplet is ---, members still receive no access through that class. Group ownership identifies the team; the permission bits specify what the team can do.
Recognize powerful groups
Some memberships grant much more than access to a project folder. Debian and Ubuntu commonly authorize the sudo group for administrative commands; Fedora and Red Hat Enterprise Linux commonly use wheel. On Debian and Ubuntu, adm allows access to many system logs. The docker group controls the Docker service and effectively provides root-level control.
Before adding someone to a group, identify what it can reach. A project group can be a narrow way to share work, while an administrative group can grant control over the whole machine.
Key Takeaways
- Every user has one primary group and can have several supplementary groups.
- New files normally take the creating process's primary group.
- A user private group usually contains only its matching user.
- Check a user's full groups with
id username;/etc/groupneed not list primary members. - Group ownership and group permission bits work together.
- Treat memberships such as
sudo,wheelanddockeras powerful access grants.
1.3 Read the passwd, shadow and group files
Linux keeps public account details separate from password data. Reading the field order helps you explain an account's identity, login setup and password policy without changing the files by hand.
Read an account record
/etc/passwd has seven colon-separated fields:
name:password:UID:GID:comment:home:shell
alice:x:1001:1001:Alice Moreau:/home/alice:/bin/bash
Alice's UID and primary GID are both 1001. The comment, also called the GECOS field, gives her full name. Her home is /home/alice, and her login shell is Bash. The x points to password data in /etc/shadow; it does not mean that her password is empty.
Ordinary users can read /etc/passwd, normally mode 644. Programs need its public details to turn stored UIDs into names. Keeping password hashes in a separate protected file prevents every local user from reading them.
Read password data
/etc/shadow has nine fields: name, password hash, last-change day, minimum age, maximum age, warning days, inactivity days, account-expiration day and a reserved field. Root can read it; some systems also grant access to the shadow group.
A password hash is a one-way result, not reversible encryption. At login the system applies the stored method and salt to the submitted password, then compares the result with the stored hash. A random salt makes the hashes differ even when two users choose the same password. SHA-512 crypt records use $6$salt$hash, optionally with a rounds=N field; yescrypt uses $y$parameters$salt$hash.
A leading ! locks the password while retaining the hash. A field containing only !, !! or * has no usable password. Other login methods, such as SSH keys, may still work with a locked password.
Work out the dates
Consider this shortened hash record:
alice:$y$j9T$...:20514:0:90:7:::
Dates count days since January 1, 1970, UTC. Day 20514 is March 2, 2026. A minimum age of 0 allows an immediate password change; a maximum of 90 means expiration on May 31, 2026. The seven-day warning begins May 24. Empty inactivity and account-expiration fields set neither limit. A last-change value of 0 forces a change at next login; a maximum of 99999 is effectively a very long password lifetime. Password expiration and account expiration are separate fields.
Read group records safely
/etc/group uses name:password:GID:members. In developers:x:1005:alice,bob, the final field lists supplementary members. Primary members are found through the GID in their passwd records. Protected /etc/gshadow stores group password and administrator data.
Use getent passwd alice or getent group developers for lookups. getent consults configured account sources as well as local files. cut -d: -f1,3 /etc/passwd displays local names and UIDs. Change records with account commands such as usermod and passwd; if direct editing is unavoidable, vipw and vigr lock the files during the edit.
Key Takeaways
/etc/passwdstores public identity and login details;xpoints to/etc/shadow./etc/shadowseparates password hashes, password aging and account expiration.- A salt makes equal passwords produce different stored hashes.
- A locked password can leave other login methods available.
- Shadow dates are day counts from January 1, 1970, UTC.
/etc/grouplists supplementary members; primary membership comes from/etc/passwd.- Use account-management commands to change records and
getentto look them up.
2Run administrative commands safely
Administrative commands can change the whole system, so the identity running them matters. Sudo lets an authorized user run a specific command with elevated rights and records the attempt; su opens another user's shell. A useful policy can grant a team one maintenance action without a general root shell. Reading the rule, editing it safely and checking its effective result are all parts of granting that access.
2.1 Use sudo and su to act as root
Administrative tasks need more access than everyday work. Keep your usual shell under your own account, and raise privileges for the action that needs them. Files created by an elevated command can belong to root even when they are inside your home directory.
Choose sudo or su
| Command | What starts | Usual password requested |
|---|---|---|
su | A shell as root | Root's password |
su - bob | A login shell as Bob | Bob's password |
sudo command | One command as root | Your own password |
sudo -u postgres psql | One command as postgres | Your own password |
A login shell loads the target user's login environment, including the home directory and startup files. Use exit to leave a shell started by su. sudo -i opens a root login shell; sudo -s opens a root shell. These are useful for a series of related administrative tasks, but every command in that shell has elevated power until you exit.
Sudo checks its policy before running the command and records the attempt. Logs may go to the system journal, /var/log/auth.log on Debian-family systems, or /var/log/secure on Red Hat-family systems. sudo -l shows the commands your account may run. Permission to use sudo is a policy decision, not a result of knowing somebody else's password.
Understand authentication
By default, sudo asks for the invoking user's password, not root's. Policy can change that behavior. Upstream sudo's authentication timestamp lasts five minutes by default; distribution settings can use another value, such as 15 minutes. The timestamp normally applies within that terminal. Run sudo -k to invalidate it when you finish.
Ubuntu normally starts with no usable root password and puts the installation user in sudo. Fedora and Red Hat-family systems commonly use wheel. A denied attempt can report that the user is not in the sudoers file; the attempt is logged.
Put the write operation under sudo
This command fails when your ordinary account cannot write /etc/hosts:
sudo echo "192.0.2.10 test.local" >> /etc/hosts
Your current shell opens the file for >> before sudo runs. Only echo receives root rights, and echo is not the program opening the destination. Give the writing job to an elevated process:
echo "192.0.2.10 test.local" | sudo tee -a /etc/hosts
Here tee opens the protected file as root. Its -a option appends; leaving that option out would replace the file's contents. For an interactive edit, sudoedit /etc/hosts, also written sudo -e /etc/hosts, runs your editor as you and handles the protected-file update.
Notice root-owned work
After sudo mkdir ~/project, inspect the result with ls -ld ~/project. The directory is in your home, but it was created by root. Its owner permissions therefore apply to root, while your account may have only read and execute access. Restore the intended owner with sudo chown alice: ~/project when Alice owns the project. The trailing colon also selects Alice's login group. Ordinary editing and file creation can then run under Alice's account.
Key Takeaways
sunormally asks for the target user's password; sudo normally asks for yours.- Use
sudo -lto inspect allowed commands andsudo -kto invalidate cached authentication. - Shell redirection happens before sudo; elevate the program that opens the protected file.
sudoeditlets your own editor work on a protected-file copy.- An elevated command can create root-owned files inside your home directory.
2.2 Grant sudo rights with the sudoers policy
A sudo rule decides who may run an action, on which host, and under which identity. Giving a team one administrative action can meet its needs without granting unrestricted control over the machine.
Read the parts of a rule
The basic pattern is who where = (as_whom) what. For example:
alice ALL=(ALL:ALL) ALL
%sudo ALL=(ALL:ALL) ALL
The first rule lets Alice run any command on any host as any user and group. The second grants the same rights to the sudo group; % marks a group name. A common Red Hat-family rule is %wheel ALL=(ALL) ALL.
To make Alice a full administrator through an existing distribution rule, run sudo usermod -aG sudo alice on Debian or Ubuntu, or use wheel on Fedora and related systems. Alice needs a new login for the membership to reach her session. The -a matters: without it, -G replaces her other supplementary groups.
Edit and check the policy
The main file is /etc/sudoers; additional rules can live in /etc/sudoers.d/. Use sudo visudo or a focused file:
sudo visudo -f /etc/sudoers.d/webteam
visudo locks the policy file during editing and checks its syntax before saving. A broken policy can leave administrators unable to use sudo. Name the file webteam, not webteam.conf: sudo's included-directory handling skips names containing a dot or ending in ~.
Files in the included directory are read in name order. When several rules match, the last matching rule controls the result; the most specific-looking rule does not necessarily win. The include is normally near the end of the main policy, so an extra file can affect a rule written earlier.
Grant one exact action
A team that maintains a web service might receive:
%webteam ALL=(root) /usr/bin/systemctl restart nginx
A member can run sudo systemctl restart nginx. The rule specifies the full command path and its arguments. It does not authorize systemctl stop nginx or bash. Check effective permissions with sudo -l; an administrator can inspect Bob's policy with sudo -l -U bob.
The allowed program also matters. A root shell can do anything. Editors and pagers may start shells, and unrestricted cp or tee can overwrite protected configuration. An apparently short command list can therefore grant full control.
Decide whether a password is needed
NOPASSWD: removes the authentication prompt for a matching command:
backup ALL=(root) NOPASSWD: /usr/local/bin/backup.sh
This can support an automated job. The script must be controlled by root: if backup can rewrite it, the account can replace its contents with any root command. Keep the permitted action narrow as well as protecting the script.
Defaults lines change policy settings. Defaults timestamp_timeout=10 sets a ten-minute authentication timestamp; Defaults logfile=/var/log/sudo.log selects an additional log file. These settings control sudo's behavior, while command rules control the actions it authorizes.
Key Takeaways
- A sudoers rule specifies who, host, target identity and permitted command.
- Edit policy with
visudoso locking and syntax checking protect the file. - An exact command with arguments can authorize one action without authorizing a shell.
- Protect scripts used by
NOPASSWDrules from changes by the invoking account. - Names containing a dot are skipped in
/etc/sudoers.d/. - When multiple rules match, their order matters.
3Create and manage user and group accounts
An account setup includes more than a login name: it needs a user ID, groups, a home, a shell and an authentication setup. Those details also change as people move between roles or leave. Group management makes team access easier, but running sessions keep the identities they already loaded. Work through creation, later changes and removal while checking both the account records and the files those records identify.
3.1 Create user accounts with useradd and adduser
Creating an account sets up an identity, a login environment and often a home directory. Choosing the options explicitly makes the result predictable across distributions.
Build a regular account
Suppose the group developers already exists. Create Priya's account and set her password in two commands:
sudo useradd -m -s /bin/bash -c "Priya Shah" -G developers priya
sudo passwd priya
-m creates /home/priya and copies the initial files from /etc/skel. -s /bin/bash selects Bash as the login shell, and -c supplies the comment. -G developers adds a supplementary membership; several group names form a comma-separated list without spaces. The account normally also receives a private primary group.
The first command adds account records to /etc/passwd and /etc/shadow, and group records as needed to /etc/group and /etc/gshadow. Its initial password field is locked, often ! or !!. The account exists before it has a usable password. passwd priya sets that password; its prompt keeps the password out of the command line.
Understand distribution defaults
useradd is the low-level account creation command used across Linux distributions. Debian and Ubuntu also provide an interactive adduser script that asks for details and creates a home. On Red Hat-family systems, adduser is another name for useradd, so it does not provide the same interactive workflow.
Without explicit options, useradd depends on local defaults. Red Hat-family defaults commonly create a home; Debian and Ubuntu defaults do not unless -m is supplied. The default shell may also differ. Inspect useradd -D for defaults such as the home base and shell. /etc/default/useradd and /etc/login.defs provide settings including UID ranges, private groups and password aging.
Supply a different home or identity
Useful options describe separate parts of the account:
| Option | Purpose |
|---|---|
-u 1500 | Choose a UID |
-g staff | Select an existing primary group |
-d /data/priya | Set the home path |
-e 2026-12-31 | Set an account-expiration date |
-r | Create a system account |
A home path in the record does not itself create the directory. Combine -d with -m when the new home must be created. On Debian, omitting -m can leave an otherwise valid account with no home directory to use at login.
For a service identity, sudo useradd -r -s /usr/sbin/nologin backupsvc requests a system UID and a noninteractive shell. System accounts have no home by default. The nologin shell prevents an ordinary interactive shell login under that identity.
Verify the setup
Run getent passwd priya, id priya and ls -la /home/priya. Check the home path, shell, primary group, extra groups and copied hidden files. /etc/skel is a template: adding .bash_aliases there affects later home creation, not homes that already exist. Use simple lowercase account names with digits, hyphens or underscores after the initial letter; spaces and unusual names are rejected or mishandled by many tools.
Key Takeaways
- Use
useradd -mto create a home and copy/etc/skel. - Set the initial password separately with
passwd. -gchooses a primary group;-Gchooses supplementary groups.- Debian's interactive
adduserdiffers from the Red Hat-family command of that name. useradd -rcreates a system account; a nologin shell prevents an interactive shell login.- Verify the account record, groups and home directory after creation.
3.2 Manage passwords and change or remove accounts
An account can need a new password, a different home, a temporary access block or permanent removal. These operations change different parts of the account, so identify the intended result before choosing a command.
Change or age a password
Run passwd to change your own password, normally after entering the current one. An administrator uses sudo passwd priya to set Priya's password without knowing the old one. Password-quality checks may reject short or simple choices.
sudo passwd -S priya reports password status. sudo passwd -l priya locks the password by placing ! before its hash, and sudo passwd -u priya unlocks it. sudo passwd -e priya expires the password so the user must choose another at the next login. Expiring a password is useful when issuing a temporary one.
Use sudo chage -l priya to inspect aging dates. For example:
sudo chage -M 90 -m 1 -W 7 priya
The maximum age is 90 days, the minimum between changes is one day, and warnings begin seven days before expiration. These values go into /etc/shadow. sudo chage -E 2026-12-31 priya sets the expiration date of the whole account, separately from its password lifetime.
Block access without deleting records
A password lock blocks password authentication. It does not remove SSH keys or stop every other authentication method. To disable a departing user's future account logins, lock the password and set a past account-expiration date, such as sudo usermod -e 1 priya. The value 1 is a day count in January 1970, so that date is already past. This does not terminate processes that are already running; those need separate attention.
Modify an existing account
usermod can change the comment with -c, the shell with -s, and the home path with -d. Combine -d and -m to move home contents, as in sudo usermod -d /data/priya -m priya. -l newname changes the login name, but the home and private group keep their existing names unless changed too. -L and -U lock and unlock the password.
To add a supplementary membership, run sudo usermod -aG developers priya. The -a means append. Without it, usermod -G developers priya replaces Priya's entire supplementary list; a previous sudo membership can disappear. Her primary group is a separate setting controlled by -g.
Remove the account and handle its files
sudo userdel priya deletes the account records but leaves the home. sudo userdel -r priya also removes the home and mail spool. The normal command refuses removal while the user still has running processes.
Files elsewhere retain their numeric owner UID. After account deletion, a listing may show 1003 as owner because no name maps to it. Reusing that UID for a new account gives that account ownership of the old files. Use sudo find / -nouser to locate files with no matching user, then archive or reassign them. For a departure, block future logins first, handle running activity and preserve needed files, then delete the account when those tasks are complete.
Key Takeaways
- Password locking, password expiration and account expiration serve different purposes.
- Use
chageto inspect or change password-aging and account-expiration dates. - Keep
-awithusermod -Gwhen adding groups without removing existing memberships. - Changing a login name does not rename the home directory or private group.
userdel -rremoves the home and mail spool, but files elsewhere retain the old UID.- Archive or reassign remaining files before that UID can be reused.
- Account expiration does not end processes that are already running.
3.3 Create groups and manage membership
A shared folder needs a group, members, and directory permissions that let those members work. The account database and the groups held by an already running shell can temporarily disagree after a membership change.
Create and maintain the group
sudo groupadd developers assigns the next available GID. Add -g 1500 to choose a specific GID or -r for a system group. Check with getent group developers; an empty final field means no supplementary members are listed yet.
Add a member with either command:
sudo usermod -aG developers priya
sudo gpasswd -a priya developers
sudo gpasswd -d priya developers removes that supplementary membership. sudo gpasswd -M alice,bob developers sets the entire member list, replacing what was there. Choose append, remove or replace according to the intended change.
Refresh a session's groups
After adding Priya, id priya queries the account database and shows the new membership immediately. Plain id in her existing shell reports the groups that shell is actually using. Those were established when the session began.
A new login loads the new list. newgrp developers offers another route: it starts a new shell with developers as the primary group. Use exit to leave that shell. When diagnosing a denied operation, inspect the identity in the session attempting the operation, not just the database entry.
Rename or delete a group
sudo groupmod -n devteam developers changes the name but keeps the GID. Existing files continue to refer to the same numeric group. In contrast, sudo groupmod -g 1600 developers changes the group's number. Files still carrying the old GID 1005 need attention; locate them with sudo find / -gid 1005, then use chgrp to assign the intended group.
sudo groupdel developers refuses if an existing user still has it as their primary group. Set another primary group with usermod -g before deleting it. Deleting a group name does not erase files carrying its former GID.
Set up a team folder
For Priya and Kenji's web team:
sudo groupadd webteam
sudo usermod -aG webteam priya
sudo usermod -aG webteam kenji
sudo mkdir /srv/web
sudo chgrp webteam /srv/web
sudo chmod 2770 /srv/web
After fresh logins, both users can create files in /srv/web. Mode 2770 gives owner and group rwx, others ---, and sets directory SGID. A new file takes group webteam, even when its creator's primary group is their private group. New subdirectories also inherit SGID.
The directory makes team membership useful and keeps others from entering, but each file still has its own mode. With a usual file request of 666, a creator's umask of 002 gives group write, while 022 leaves the group read-only. If team members need to edit each other's files, check these creation defaults as well as the folder.
Key Takeaways
- Use
groupaddto create groups andgpasswdorusermod -aGto add members. - Database membership changes reach an existing session after a fresh login or a suitable new shell.
- Renaming a group keeps its GID; changing its GID leaves existing file GIDs to fix.
- A group cannot be deleted while an account still uses it as its primary group.
- A shared SGID directory assigns its group to new files; each file's mode still controls editing.
4Read and change ownership and permissions
Access depends on two linked questions: which user or group owns an object, and what its permission bits allow. A long listing supplies the evidence, but a file and a directory give the same bits different jobs. Reading a document, entering a folder and deleting a name therefore need different checks. Use chmod to set the allowed actions and chown or chgrp to assign the identities to which those actions apply.
4.1 Read ownership and permissions in a listing
A long listing places the information needed for an access decision on one line. Read the owner and group together with the nine permission bits; the bits alone do not tell you which rights a particular person receives.
Decode a long listing
-rw-r----- 1 priya developers 2048 Oct 22 09:15 report.txt
The first field is the file type plus permissions. The following fields give the hard-link count, owning user, owning group, size in bytes, modification time and name. This regular file belongs to Priya and the developers group. The size is 2048 bytes; the displayed time records the last content modification.
The first character is - for a regular file, d for a directory or l for a symbolic link. You may also meet c and b for character and block devices, p for a named pipe, and s for a socket.
Split the next nine positions into three triplets:
| Class | Bits here | Ordinary file access |
|---|---|---|
| Owner | rw- | Read and change contents |
| Group | r-- | Read contents |
| Others | --- | No access through this class |
Within every triplet, the positions mean read, write and execute, in that order. A dash marks a missing permission, not an empty slot to skip when counting.
Choose exactly one class
For an ordinary permission check, Linux asks:
- Does the process's user match the file owner? Use the owner triplet.
- Otherwise, does one of its groups match the file's group? Use the group triplet.
- Otherwise, use the others triplet.
The classes do not add together. Suppose Priya owns a file whose full type-and-mode string is ----rw-rw-. Her owner triplet is ---, so she cannot read it through the ordinary bits, even though group and others have rw-. As owner she can change the mode. A less restrictive group or others triplet does not override the selected owner's triplet.
Root can bypass ordinary read and write permission checks. To execute a regular program file, even root needs at least one execute bit on it. A mode check therefore needs both the user's identity and the operation being attempted.
Inspect directories and numbers
ls -ld /srv/web lists the directory itself. Without -d, ls -l /srv/web normally lists entries inside it, which can distract you from a restriction on the directory. ls -a includes hidden names, while ls -n displays numeric owners and groups. Files store UIDs and GIDs; if an account or group has been deleted, an ordinary listing can show the remaining number too.
For a compact report, run:
stat -c '%A %a %U %G %n' report.txt
It can show -rw-r----- 640 priya developers report.txt, placing letters and octal digits side by side. A + after the letters signals extra access-control-list entries. A symbolic link commonly displays lrwxrwxrwx; Linux uses the target's permissions for access, not those displayed link bits.
Key Takeaways
- Read the file type first, then owner, group and others triplets.
- The first matching class supplies the ordinary permissions; classes do not combine.
- Files store numeric UIDs and GIDs even when a listing shows names.
ls -ldinspects the directory itself, andstatcan show both letter and octal modes.
4.2 Explain what read, write and execute allow
Read, write and execute describe different actions on files and directories. A directory stores names leading to files, so changing a file's contents and removing its name are different permission checks.
Match the bit to the object
| Bit | Regular file | Directory |
|---|---|---|
r | Read or copy contents | List entry names |
w | Change, overwrite or append contents | Create, delete or rename entries, with x |
x | Run as a program | Enter and reach named entries |
A file with write permission but no read permission can be appended to without being read. For example, a shell can open a writable log for echo text >> log.txt even when cat log.txt fails. An editor often needs both read and write because it first loads the existing contents.
A script run as ./backup.sh needs execute permission and must be readable by its interpreter. If the script is readable but lacks execute, bash backup.sh can still read and run it: Bash is the executable program in that command.
Separate listing from searching
Directory read permission lets you see names. Directory execute, also called search permission, lets you reach an entry by name. With read but no execute, ls can show names, while ls -l cannot obtain their details and may display errors and question marks. You cannot open the named files through that directory.
With execute but no read, the reverse is possible: you can reach notes.txt if you already know its exact name, but cannot list the directory to discover the names. The file's own mode must still allow the requested access.
Trace the whole path
To read /home/priya/notes/public.txt, Kenji needs execute permission on every directory in the path and read permission on the file. If /home/priya is mode 700, its others triplet is ---; Kenji stops there even if public.txt is mode 644. Adding more read permission to the file cannot repair a missing directory search bit above it.
Use ls -ld /home/priya /home/priya/notes to inspect the directories themselves. At each level, choose the class that applies to Kenji and check its execute bit. The relevant class can change from one directory to the next because their owners and groups can differ.
Predict deletion and renaming
Deleting a file removes a directory entry. Kenji needs write and execute on the containing directory, not write on the file. In an ordinary writable directory without the sticky bit, he can remove Priya's read-only file. Conversely, owning a file does not let him delete it from a directory where he lacks write permission.
Removing file write is therefore useful for protecting contents from edits, but it does not protect the name from removal. A directory's sticky bit adds an ownership restriction on deletion and renaming in shared writable folders. File access and directory-entry access answer separate questions.
Key Takeaways
- File
r,wandxcontrol reading, changing and running the file. - Directory
rlists names;xreaches entries;wwithxchanges entries. - Reaching a file requires execute on every directory in its path.
- A readable script can be passed to its interpreter even without its own execute bit.
- Deleting a file depends on its directory's permissions, with an additional restriction in sticky directories.
4.3 Change permissions with chmod
Use chmod to change the permissions of a file or directory you own. Root can change them too. Having write access through a group lets you change file contents, but does not make you the owner or let you set its mode.
Make a focused symbolic change
A symbolic mode has a class, an operator and bits. The classes are u for owner, g for group, o for others and a for all three. + adds permissions, - removes them and = sets that class exactly.
chmod u+x deploy.sh
chmod go-w notes.txt
chmod u=rw,g=r,o= report.txt
The first command adds only the owner's execute bit. The second removes group and others write while retaining their other bits. The third gives the owner read/write, the group read, and others no permissions: rw-r-----.
Specify the class when you want a precise change. If you omit it, as in chmod +w notes.txt, the umask restricts which class bits are affected. With umask 022, that command adds write for the owner only; chmod a+w notes.txt explicitly includes all three classes.
Convert each triplet to an octal digit
Read has value 4, write 2 and execute 1. Add the values present in each class:
| Digit | Bits | Calculation |
|---|---|---|
| 7 | rwx | 4 + 2 + 1 |
| 6 | rw- | 4 + 2 |
| 5 | r-x | 4 + 1 |
| 4 | r-- | 4 |
| 0 | --- | None |
For rw-r-----, split into rw-, r--, ---: the digits are 6, 4, 0. chmod 640 report.txt sets those nine ordinary bits, regardless of the previous ordinary mode. Reverse the process for 750: 7 gives rwx, 5 gives r-x, and 0 gives ---, forming rwxr-x---.
Choose a useful final mode
Mode 600 keeps a file private to its owner. Mode 644 lets other users read an ordinary file. Mode 664 also lets the group edit. Private directories commonly use 700, group-readable directories 750, and group-writable directories 770. Programs or public directories commonly use 755.
The same digits mean different useful actions on different objects. Applying 644 to a directory removes execute from every class. Even its owner can no longer enter it or open files through it. Use a directory mode with search permission for the people who need access.
Apply changes through a tree
chmod -R 755 site/ also makes every ordinary file executable. For a tree containing directories and ordinary documents, use conditional execute:
chmod -R u=rwX,go=rX site/
Capital X adds execute to directories and to files that already have an execute bit. Non-executable files become 644; directories become 755. Existing executable files retain execute access. This keeps traversal possible without marking every document as a program. Special bits are separate: GNU chmod preserves directory SUID and SGID unless you explicitly clear them, such as with chmod g-s site/.
Key Takeaways
- Only the owner or root can change a file's mode.
- Symbolic
+and-change selected bits;=sets a class exactly. - Octal modes add read 4, write 2 and execute 1 for each class.
- An omitted class in symbolic mode makes the umask relevant.
- Directories need search permission for users who must reach their entries.
- Capital
Xsupports recursive changes without making every ordinary file executable.
4.4 Change ownership with chown and chgrp
Ownership identifies the user and group whose permission triplets will be checked. Correct ownership can fix a working folder that was accidentally created with sudo, without granting broader access to everybody else.
Read the chown forms
chown can change a user, a group or both:
| Command | Result |
|---|---|
sudo chown kenji report.txt | Change owner; keep the group |
sudo chown kenji:webteam report.txt | Change owner and group |
sudo chown :webteam report.txt | Change only the group |
sudo chown kenji: report.txt | Set owner and Kenji's login group |
chgrp webteam report.txt | Change only the group |
Numeric IDs work too, as in sudo chown 1002:1005 report.txt. The names are resolved to numbers; the file stores those numbers.
Only root can transfer a file to another owning user. An owner can change their own file's group to a group they belong to. Thus Priya can use chgrp webteam plan.txt if she owns the file and belongs to webteam. Membership in finance would also be required to assign it to that group. Another member's ability to edit the file does not grant the ability to change its owner or mode.
Repair an accidental root-owned folder
Kenji ran a creation command with sudo. The listing is:
drwxr-xr-x 2 root root 4096 Oct 22 10:02 /home/kenji/app
He is not the owner and is not using the owning group, so he receives others' r-x. He can inspect and enter the folder, but cannot create entries because write is missing. Making the folder writable by everyone would grant more access than his project needs.
If the project belongs to Kenji, sudo chown -R kenji: ~/app restores his ownership and login group throughout it. His owner triplet is now rwx, so he can create files. Inspect the target path before any recursive ownership command: applying it to /etc or /usr can break system operation. -R means the directory and everything beneath it.
Predict ownership after file operations
A newly created file belongs to the creating process's user. Its group normally comes from that process's primary group, or from an SGID parent directory. Creating an ordinary new copy with cp therefore makes the caller its owner. A same-file-system mv changes the location of an existing file and keeps its owner and group. Copy options that preserve ownership are a separate behavior from an ordinary new copy.
This distinction explains why moving an old file into a shared folder does not apply that folder's group-inheritance rule to it. SGID applies at creation; use chgrp when an existing file's group needs changing.
Combine identity with access
Assigning webteam with chgrp selects who the group class represents. It does not add group read or write. Use chmod to grant the required bits after choosing the group. Changing ownership of an executable can also clear SUID or SGID privileges; inspect its resulting mode when those bits matter.
Key Takeaways
chownassigns the owning user or group;chgrpchanges only the group.- Only root can change the owning user.
- Owners may assign their files to groups they belong to.
- A new copy normally belongs to its creator; a same-file-system move keeps ownership.
- SGID inheritance applies to newly created files, not an existing file moved into the directory.
5Control default and special permissions and solve access problems
New files inherit creation settings, while special permission bits change how programs or shared directories behave. A team folder works only when its group, inherited group ownership and new file modes agree. When access fails, follow the actual user and path to the first missing right. That diagnosis lets you repair the needed permission while keeping private data and administrator powers restricted.
5.1 Set default permissions with umask
The permissions on a new file come from two inputs: the mode its creating program requests and the process's umask. The mask removes requested bits; it never adds permissions the program did not ask for.
Start with the creation request
Editors and shell redirection usually request 666, or rw-rw-rw-, for ordinary new files. Directory creation usually requests 777, or rwxrwxrwx. A umask is a set of bits to clear from that request. A bit survives only when the request includes it and the mask does not.
For umask 022, keep all requested owner bits, remove group write, and remove others write. A file becomes 644; a directory becomes 755. Read each digit as bits, not as an ordinary decimal amount.
| Mask | File requested as 666 | Directory requested as 777 |
|---|---|---|
| 022 | 644 | 755 |
| 027 | 640 | 750 |
| 077 | 600 | 700 |
| 002 | 664 | 775 |
| 033 | 644 | 744 |
With 027, the group loses write while others lose all three bits. It is useful when a team should read new files but users outside the team should have no access. With 002, group write remains available; the file's owning group still determines who receives it.
Why subtraction fails
Take the file request 666 and mask 033. Each 3 means write plus execute. But each requested file triplet is rw-: execute is already absent. Clearing write and execute leaves r-- for group and others, so the result is 644. Subtracting digits would produce 633, which wrongly suggests execute bits can appear.
For a directory request of 777, clearing those same bits gives 744. That directory lacks group and others execute, so those classes cannot reach its entries even though they can list names. A mask that gives the desired file mode may have an inconvenient directory result.
Inspect and set your mask
Run umask to see the current setting, often displayed with a leading zero, such as 0022. The leading zero is formatting; Linux uses the nine ordinary permission bits. umask -S prints allowed bits, such as u=rwx,g=rx,o=rx for 022; a program can request a subset of those bits.
umask 027 changes the current shell and is inherited by programs it starts. Existing files keep their modes. Use chmod when an already created file needs different rights.
Choose a persistent default
A line such as umask 027 in ~/.profile or ~/.bashrc can set the value for the shells that read that startup file. System defaults can come from /etc/profile or UMASK in /etc/login.defs. Distribution and account setup determine which files are read and when.
Many systems use 022, while private-group setups often use 002 for regular users. A compiler can request executable output with mode 777; under 022 it becomes 755. A text editor's request of 666 has no execute bits, so writing a script does not itself make that script executable.
Key Takeaways
- A new mode keeps bits requested by the program unless the umask removes them.
- Ordinary file requests usually start at 666; directory requests usually start at 777.
- Apply the mask bit by bit; decimal-style subtraction can give the wrong result.
- Changing the mask affects later creations, not existing files.
- An inherited shell mask and a program's requested mode are separate inputs.
- Check both the file and directory results when selecting a default.
5.2 Use SUID, SGID and the sticky bit
Three special bits add behavior beyond the ordinary owner, group and others permissions. Their meaning depends on whether the object is a program or a directory.
Recognize the extra digit
A leading octal digit combines SUID 4, SGID 2 and sticky 1. Mode 4755 is SUID plus ordinary mode 755. Mode 2770 is SGID plus 770. Mode 3770 combines SGID and sticky because 2 plus 1 is 3.
In a long listing, the bits share execute positions. Lowercase s in the owner slot means SUID and owner execute; lowercase s in the group slot means SGID and group execute. A lowercase t in the others slot means sticky and others execute. Uppercase S or T means the special bit is present but execute in that position is absent.
SUID and SGID on programs
SUID lets an executable run with its file owner's effective identity. /usr/bin/passwd commonly appears as -rwsr-xr-x root root: the program can update protected password data while enforcing which user's password the caller may change. Starting it does not give the caller a root shell. Linux ignores SUID on scripts and directories.
SGID on an executable similarly uses the file's group identity. These bits grant program-controlled access, so the program's behavior matters. Never add SUID to a shell, editor or script. An administrator can inventory SUID regular files with sudo find / -perm -4000 -type f 2>/dev/null; use -perm -2000 for SGID files and compare results with the expected system setup.
SGID on a team directory
On a directory, SGID makes new entries take the directory's group, and new subdirectories inherit SGID. Suppose /srv/web belongs to root:webteam, mode 2770, displayed as drwxrws---. Priya has a private primary group but belongs to webteam. When she creates index.html inside this directory, its group becomes webteam.
Its ordinary mode still depends on creation. With a file request of 666 and umask 002, it becomes 664 and Kenji, another team member, can edit it. With 022 it becomes 644, so Kenji has read access only. SGID supplies the group, not an extra write bit.
Sticky directories and deletion
The sticky bit restricts deletion and renaming: with the needed directory access, an entry can be removed by its file owner, the directory owner or root. This makes shared writable directories useful without letting users remove each other's entries. /tmp and /var/tmp commonly use 1777, displayed as drwxrwxrwt. Sticky does not prevent edits to file contents when the file mode permits them. Linux ignores it on regular files.
Set bits with chmod u+s prog, chmod g+s /srv/web or chmod o+t /srv/drop. Clear them with u-s, g-s or o-t. With GNU chmod, chmod 755 /srv/web preserves an existing directory SGID bit; use chmod g-s /srv/web to clear it explicitly.
Key Takeaways
- SUID uses a program file's owner identity; executable SGID uses its group identity.
- Directory SGID gives new files its group and passes SGID to new subdirectories.
- A sticky directory restricts deletion and renaming by ownership.
- Lowercase
sortincludes execute; uppercaseSorTlacks execute in that position. - SGID group inheritance and the new file's write permission are separate.
- GNU chmod preserves directory SGID when a three-digit mode is used.
- Sticky protects entries from removal, not writable contents from editing.
5.3 Diagnose permission problems and apply least privilege
A "Permission denied" error identifies a failed operation, not necessarily a bad file mode. The block may be your session's groups, a parent directory, the file itself or ownership left by an elevated command.
Trace identity, path, class and operation
Start with plain id in the affected session. If a group was recently added, compare the active list with id username, which queries the database. A fresh login can load the new membership.
Next inspect the entire path:
namei -l /srv/reports/q3.txt
namei -l reports owners, groups and modes along the path. You can also inspect each directory with ls -ld. At every object, select the first matching class: owner, otherwise group, otherwise others. Then ask what the attempted operation needs. Reading needs file r and search permission on all parent directories. Creating, removing or renaming an entry needs w and x on its directory, with sticky restrictions where present.
Find the first blocked operation
Kenji belongs to finance and tries cat /srv/reports/q3.txt. The relevant objects are:
drwxr-xr-x root root /srv
drwxr-x--- root finance /srv/reports
-rw------- maria finance /srv/reports/q3.txt
Kenji can pass through /srv using others execute. In /srv/reports, his finance membership selects group r-x, so he can pass through there too. On q3.txt, he is not Maria, and the finance triplet is ---. The missing permission is file group read.
If finance members should read the report, Maria or root can run chmod g+r /srv/reports/q3.txt. The resulting mode is 640. It supplies the missing right without giving the group write or opening the report to others. An administrator can test with sudo -u kenji cat /srv/reports/q3.txt, running the command as Kenji rather than testing it as root.
Choose the smallest repair
A correct fix may be adding a team membership, setting group read, restoring a project's owner or adding directory search for the intended class. chmod -R 777 hands every local account write access throughout the tree and makes ordinary files executable. It also cannot solve every cause of an access failure.
Check common causes before editing a large tree: inactive new membership, missing parent x, root-owned work created with sudo, and new files whose umask removed needed team access. FAT32 and exFAT drives do not store native Linux UIDs, GIDs and modes; mount options supply those values, so per-file chmod or chown can fail or have no effect.
Keep private data private
An SSH private key such as ~/.ssh/id_ed25519 should normally be mode 600; its .ssh directory is usually 700. SSH checks private-key protection and can reject an overly accessible key. /etc/shadow remains inaccessible to ordinary users. Full sudo administrators can bypass ordinary file privacy, so keep that group small and grant specific actions when full administration is unnecessary.
Key Takeaways
- Check the affected session's identity and active groups before changing file modes.
- Inspect every parent directory as well as the target file.
- Match the permission to the operation and use the smallest necessary change.
- Test the result as the affected user; a root test can hide a missing ordinary permission.
- Creation defaults and non-Linux file systems can explain surprising modes.
Linux Users, Groups and Permissions examples
1Read an identity and its account records
13 steps
- 1IntroductionStart with the identity doing the work
A file request comes from a running process, and that process carries a user identity and groups. You will read Alice's identity, connect it to account records and distinguish current sessions from stored account details. These are the clues you need before deciding what access her commands receive.
- 2ExplanationA number gives root its power
Linux uses a UID, not the spelling of a name, to identify a user. UID 0 is root; regular accounts commonly begin at 1000. Services usually run under limited system accounts with a nologin shell. A service therefore does not need a person's login or full root rights to do its own work.
- 3ExampleRead Alice's id output
Alice runs
idand sees:uid=1001(alice) gid=1001(alice) groups=1001(alice),27(sudo),1005(developers)The UID identifies Alice. The GID is her primary group. The final list includes her primary group plus sudo and developers. UID 1001 is not root, even though the sudo group may authorize selected elevated commands.
- 4ChallengeA powerful name or a powerful UID?
An account named
maintainerhas UID 0. Another namedroot-helperhas UID 1030. Which identity has root power without using sudo, and why?---reveal---
Maintainer has root power because its UID is 0. The root-helper name does not change UID 1030 into the superuser identity. Inspect the number, not a suggestive name or a customized prompt.
- 5ConnectionIdentity and login history answer different questions
whoamiidentifies the current user;idadds IDs and groups.wholists current login sessions, andwadds activity, uptime and load.lastreports recorded past logins and reboots. On systems using wtmpdb, such as Debian 13, usewtmpdb lastfor that history. A history entry is not the group list of your current shell. - 6ExplanationShare through an extra group
Alice's primary group is her private group, also named alice. Developers is an extra supplementary group. A process can use both primary and supplementary memberships for group access. Giving a report to developers can therefore share it with Alice and Bob, while assigning it to Alice's private group normally does not share it with coworkers.
- 7ExampleConnect a report to developers
The report belongs to
bob:developers, moderw-r-----. Alice is not its owner, but her developers membership selects groupr--: she may read, not edit. Chen is outside developers and receives others---. Setting the owning group identifies the team; the middle triplet determines the team's allowed actions. - 8ChallengeAn empty list with a real member
An account record gives Robin primary GID 1440. The group lookup returns
review:x:1440:. Is Robin a review member despite the empty final field?---reveal---
Yes. Robin's primary GID matches review. The final group field lists supplementary members, so it need not include primary members. A full user lookup with
id robinchecks both membership kinds. - 9ExampleSplit the public account line
Read
alice:x:1001:1001:Alice Moreau:/home/alice:/bin/bashas seven colon-separated fields. Alice is the name, x points to protected password data, 1001 is the UID, and the next 1001 is the primary GID. The remaining fields give a comment, home and login shell. The public passwd record does not contain Alice's readable password. - 10ExplanationA hash is checked, not decrypted
The shadow file stores password hashes and aging fields with restricted access. At login, the password is hashed with the stored method and salt, then compared with the saved result. Different salts let equal passwords have different hashes. A leading
!locks password authentication, but it does not remove every other login method. - 11ExampleRead the aging fields
In
alice:$y$j9T$...:20514:0:90:7:::, day 20514 is March 2, 2026. Minimum age 0 allows another change immediately. Maximum age 90 puts expiration on May 31, and warning 7 begins May 24. The empty inactivity and account-expiration fields set neither of those limits. All date values use days since January 1, 1970, UTC. - 12ChallengeSeparate password failure from identity
A lookup shows an account with UID 1090, primary group 1090 and a shadow hash prefixed by
!. A teammate says, "The account is gone, so its group no longer matters." What is wrong?---reveal---
The account still exists with its UID and group. The prefix locks its password; it does not delete its identity. Its files and group memberships still have meaning, and a non-password login method may still be available.
- 13RecapChoose the right evidence
Use the active process identity to understand who is acting. Group membership connects that identity to shared rights. Passwd and group records describe public account relationships; shadow holds protected password and aging data. Query with
getent, and use account-management commands when records need changing.
2Elevate one action and read its policy
13 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionKeep the administrative action in view
- 2ExplanationSwitch a shell or run one command
- 3TipCheck rights and temporary authentication
- 4ChallengeWhose password for another target?
- 5ExampleFollow the failed append
- 6ExampleGive the writer elevated rights
- 7ChallengePreserve the old contents
- 8ExplanationRead a complete authorization
- 9TipEdit a rule with syntax protection
- 10ChallengeA restart grant is not a stop grant
- 11Key InsightA script can widen a narrow rule
- 12ChallengeCheck both the policy and the process
- 13RecapKeep the scope as narrow as the task
3Create an account and make team access work
15 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionSet up a usable working identity
- 2ExampleCreate the account explicitly
- 3ExplanationComplete the password and home setup
- 4TipCheck the result in three places
- 5ChallengeA home path without a home
- 6ExplanationChoose a password or account change
- 7ExampleSet aging without confusing dates
- 8ChallengeKeep existing team memberships
- 9ExplanationAdd and remove group members
- 10ExampleCompare database and session
- 11ChallengeFix the session before the files
- 12ConnectionGive the team a shared creation point
- 13Key InsightDeletion leaves numeric ownership behind
- 14ChallengeA departure has several separate effects
- 15RecapVerify the records and the working session
4Read a mode and predict an operation
17 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionAsk what the user is trying to do
- 2ExampleBreak the listing into fields
- 3ExplanationSelect the first matching triplet
- 4ChallengeThe group does not override the owner
- 5ExplanationUse each object's meaning of x
- 6ExampleWalk through a blocked path
- 7ChallengeA read-only file in a writable folder
- 8Key InsightAn interpreter reads a script
- 9ExplanationAdd, remove or set a class
- 10ExampleConvert 750 one class at a time
- 11TipKeep directories searchable in a tree
- 12ChallengeAdd one right without replacing the rest
- 13ExplanationAssign the right identities
- 14ExampleRepair the owner of a working folder
- 15ChallengeMove or create a new copy?
- 16ChallengeChoose a mode fix or an owner fix
- 17RecapConnect the identity, object and action
5Control new modes and trace a denied request
19 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionExplain the mode before changing it
- 2ExplanationStart from what the program requests
- 3ExampleApply mask 027 to a file
- 4ExampleTest the subtraction shortcut
- 5ChallengePredict two creation results
- 6TipSeparate future defaults from existing files
- 7ExplanationRecognize special bits in the display
- 8ExampleA program gets controlled extra power
- 9ExampleFollow a new file into the team folder
- 10ExplanationProtect names in a shared writable directory
- 11ChallengeEdit without permission to delete
- 12TipClear a special bit explicitly
- 13ExplanationAsk four diagnostic questions
- 14ExampleCheck Kenji's path first
- 15ExampleLocate the missing right
- 16ChallengeStop at the blocked parent
- 17ConnectionCheck the cause behind surprising results
- 18ChallengeA new default and an existing file need different fixes
- 19RecapKeep each permission mechanism distinct
Linux Users, Groups and Permissions practice questions
Set 1: Manage accounts and shared files10 Practice Questions
Question 1 of 10
rwxr-----?Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
brief.txt and belongs to writers, but not sales. What group change may she make without sudo?Show answerHide answer
Question 4 of 10
sudo -u postgres psql request?Show answerHide answer
-u changes the command's target user, not whose password is checked. Asking for postgres's password describes the usual su behavior instead.Question 5 of 10
sudo and editors. An administrator runs usermod -G reviewers mei. What is her supplementary list in a fresh login?Show answerHide answer
-a, usermod treats the supplied -G list as the complete supplementary list. Mei therefore loses both previous supplementary memberships. Keeping the old groups would require append mode, -aG; the command does not give sudo membership special protection.Question 6 of 10
/data/zoe, created now, and Bash as its shell. What command requests all three?Show answerHide answer
-d selects the home path, -m creates it, and -s sets the login shell. A command with only -d records a path but does not explicitly request directory creation. The comment option -c cannot replace either a home-path option or a shell option.Question 7 of 10
audit to records without changing its GID. What happens to files assigned to that GID?Show answerHide answer
records after the rename. Losing group ownership is the concern when the numeric GID changes without updating the files, not when only the label changes.Question 8 of 10
/srv/art is root:artists mode 2770. Inez belongs to artists, has primary group inez and umask 027. She creates a file requesting 666. What group and ordinary mode result?Show answerHide answer
Question 9 of 10
%ops ALL=(root) /usr/bin/systemctl reload nginx. What action does it authorize?Show answerHide answer
Question 10 of 10
lab. /srv is 755, /srv/lab is root:lab mode 740, and its file is ana:lab mode 640. All earlier parents are searchable. What smallest class change lets Niko read the file?Show answerHide answer
/srv/lab is r--, so he cannot search that directory. Adding group execute supplies the missing path right. Adding file read for others would not help because the directory still blocks the path and Niko uses the group class.Set 2: Identify accounts and control access10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
rescue has UID 0. What administrative power does that identity have?Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
design:x:1420:. Does the empty final field mean the account is outside design?Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
nora:x:1042:1042:Nora:/home/nora:/bin/bash, what does x mean?Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
sudo echo "ready" >> /etc/team-status fail when the file is root-writable only?Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
id lena includes media, but plain id in Lena's old shell does not. What should Lena do before retrying group access?Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
004 and belongs to its owning group. What ordinary permission class controls his read attempt?Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
docs. /srv is root:root mode 755, /srv/notes is root:docs mode 750, and a.txt inside it is maya:docs mode 440. Can Tariq read and delete it using ordinary permissions?Show answerHide answer
Save this lesson to see this answer.
Set 3: Predict modes and directory access10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
check.sh while keeping other bits?Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
/srv/box. She knows a file's exact name, and that file gives her read. What can she do?Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
umask 077?Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
drwxr-S--- say about the group's SGID and execute bits?Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
ben:ben is moved into an SGID team folder on the same file system. What ownership does it retain?Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
/srv/drop is root:shared mode 3770. Dev and Eva are active members of shared. Eva creates a file requesting 666 with umask 002. Can Dev edit and delete her file under ordinary permissions?Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
chmod -R u=rwX,g=rX,o= tree/ produce?Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
root:review mode 705. Sam belongs to review and is not root. What directory rights does Sam receive from the ordinary classes?Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
x.txt but cannot rename it inside root:team mode 1750; Oli is in team and owns x.txt. Which smallest permission change enables the rename while retaining sticky?Show answerHide answer
Save this lesson to see this answer.
Set 4: Choose safe administrative changes10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
/etc/sudoers.d/, but the valid rule in release.conf is not applied. What filename change allows that rule file to be read?Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
draft.txt to authors?Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
pat with UID 1088 is deleted, leaving /data/archive owned by 1088. A new account receives UID 1088. What explains its access to that archive as owner?Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
memo in /srv/review. The directory is root:review 2750 and memo is jo:review 640; Rae is in review. Rae only needs in-place content changes. What smallest fix meets that need?Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
chmod 750 team/, then creates a subdirectory inside it. What special-bit behavior should they expect?Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
research is still Kim's primary group. Why does ordinary groupdel research refuse, even after Kim is removed from its supplementary member list?Show answerHide answer
Save this lesson to see this answer.
Set 5: Trace access across users and paths10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
/srv is 755; /srv/qa is root:qa mode 2710, and result inside is lee:qa mode 640. All earlier parents are searchable. Can Uma list names, read the known file and create a new file?Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
/var/log/team-run. What command elevates the writing process and preserves prior contents?Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
cp. Who owns the new destination file?Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
edit. /srv/edit is root:edit 2770. Noor can create files there, but an existing kai:edit file is 640 and she cannot append. Creators use programs requesting mode 666. What change to future ordinary file creation lets teammates append without opening files to others?Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
drwxrwx---, owner teo, group build. Teo is also in build. What class is used for Teo's ordinary access?Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
mira:team mode 1770. Ren is in team; Sol owns an entry there. Who among Mira and Ren may delete Sol's entry under the ordinary bits and sticky rule?Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
NOPASSWD: /usr/bin/systemctl restart nginx to ops, then a later matching rule uses PASSWD: for that same command. With no valid timestamp, what happens on that permitted action?Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
A
Account expiration
Accountability
ACL marker
-rw-r-----+ has an ACL marker beyond the nine ordinary permission positions.Active groups
id shows the active groups in a user's old shell before they start a new login session.Adduser
adduser asks for account details and creates the new user's home during setup.Authentication timestamp
sudo -k.B
Bit removal
C
Chage
chage -l lea to inspect the dates before changing the account's aging settings.Chgrp
chgrp editors draft.txt on their own file after joining the editors group.Chmod
chmod g+w draft.txt to let the owning group of their file change the document's contents.Chown
chown lea:editors draft.txt to assign both the file's owner and its group.Conditional execute
X, which selects execute for directories and files that already have an execute bit.Creation request
D
Defaults entry
timestamp_timeout=10 sets a ten-minute authentication interval.Directory entry
E
Effective user ID
Execute permission
G
GECOS field
priya, the GECOS field contains "Priya Shah" while the login name stays the shorter priya.Gpasswd
gpasswd -a lea editors adds Lea without replacing the editors group's other supplementary members.Group
editors makes its group permission triplet useful to that team.Group class
Group file
/etc/group stores group names, password placeholders, GIDs and lists of supplementary member names.Group ID
Group inheritance
editors, group inheritance makes a new report belong to editors, but its own mode decides whether editors may write.Groupadd
groupadd, the administrator confirms the new team group with getent group.Groupmod
groupmod name change keeps the GID, so files continue to resolve to the renamed group.H
Home directory
/home./data/lea still needs to be created if it does not already exist.I
Inherited mask
Interpreter
task.sh through bash task.sh even when the script has no execute bit.L
Least privilege
Login shell
sudo -i starts a root login shell, so later commands in that shell run under root's identity.M
Mount options
N
Namei
-l output shows ownership and permission information for components along a file path.namei -l to find a parent directory that blocks access to a readable file.Newgrp
newgrp editors and checks the new shell's identity with id.Nologin shell
NOPASSWD tag
Numeric ownership
O
Octal mode
rwx, the group gets r-x and others get no permissions.Orphaned file
Others class
--- on a mode-640 report.Owner class
P
Passwd file
/etc/passwd, storing names, IDs, home paths, comments and login shells./home.Password expiration
passwd -e triggers password expiration so a user must replace an issued temporary password.Password hash
Password inactivity period
Password lock
!.Permission triplet
r--, so its members can read but not edit the file.Primary group
mina, a new file normally starts with that group outside an SGID folder.Process
R
Read permission
Recursive change
-R option.Redirection
>>.sudo echo starts because the ordinary shell opens the protected file.Root
Runas specification
(root) restricts a maintenance action to running under the root identity.S
Salt
Same-file-system move
Search permission
SGID
Shadow file
/etc/shadow that stores local password hashes and account-aging fields.Skeleton directory
/etc/skel..bash_aliases to the skeleton directory for accounts created afterward.Special-mode digit
Sticky bit
/tmp lets users create temporary files without letting them remove each other's entries.Su
su - bob to start Bob's login environment, then types exit to return to their own shell.Sudo
sudo for a service restart, then edits their own project files without elevated rights.Sudoers policy
SUID
Supplementary group
design lets a user use design's rights on shared files.Symbolic mode
g+w to add group write.go-w removes group and others write while keeping their remaining permissions.System account
www-data lets a web service run without using a person's regular account.U
Umask
User account
User ID
uid=1051(ava) identifies Ava even if her account name is later changed.User private group
Useradd
useradd with -m and -s to create a home and select a login shell.Usermod
-a to usermod -G preserves earlier supplementary memberships while appending a new one.V
Visudo
visudo on a team policy file so a typo is detected before it is saved.W
Write permission
- 1Linux and Open Source
- 2Linux Command Line
- 3Linux Text Processing
- 4Shell Scripting
- 5Linux Users, Groups and Permissions
- 6Linux Processes, Packages and Services
- 7Linux Storage and Networking
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.