Skip to content

Changing ownership and permissions

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

Your report should be readable by a project teammate, but nobody outside that group. A permission string describes the policy; it does not prove that the intended account can actually use the file.

By the end, you can change ordinary permission bits symbolically and numerically, change owning users and groups, and verify the result with both metadata and real access tests.

Finish File versus directory permissions. Keep your B04 lab directory. Use a disposable lab VM or container. The names sam and team are reserved for this exercise; do not reuse accounts or groups containing somebody else’s work. Begin from a clean lab state or complete Reset this lesson first.

Some setup commands need administration rights. Prefixing one command with sudo runs that command as root after your own password, if policy permits it. Your shell remains learner. Type your lab account’s password at the prompt; nothing appears while you type. B11.5 explains delegation and authentication in detail.

Terminal window
mkdir -p ~/lab/b11/changes
cd ~/lab/b11/changes
sudo useradd -m -s /bin/bash sam
sudo groupadd team
sudo usermod -aG team sam
sudo usermod -aG team learner

This creates a practice account with a home directory and Bash shell, creates team, then adds each account to that supplementary group. -aG adds membership without replacing the existing supplementary memberships. Replace the final learner only if your VM account has another name. Do not assign a password to sam; the access tests use sudo from your authorized account.

Answer sudo without showing the password
learner@rootvolt:~/lab/b11/changes$ sudo useradd -m -s /bin/bash sam[sudo] password for learner: learner@rootvolt:~/lab/b11/changes$ 

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. The first sudo command asks for learner's password; the replay shows no password characters.
Steps (5)
  1. Type sudo useradd -m -s /bin/bash sam
  2. Press Enter
  3. Output: [sudo] password for learner:
  4. Type the password (the terminal shows nothing)
  5. Press Enter — Type the password (not shown) and press Enter

Check the current shell against the configured accounts:

Terminal window
id -Gn
Captured output
learner sudo
Terminal window
id learner
Captured output
uid=1001(learner) gid=1001(learner) groups=1001(learner),27(sudo),1003(team)
Terminal window
id sam
Captured output
uid=1002(sam) gid=1002(sam) groups=1002(sam),1003(team)

Notice that id -Gn does not include team, while the named-account lookup does. Configuration changed; the already-running shell’s supplementary groups did not. Keep this shell open so the later comparison uses the same identity.

State the owner, group, and other permissions

Section titled “State the owner, group, and other permissions”

Create the disposable report and establish its starting mode:

Terminal window
printf 'Team review\n' > report.txt
chmod 644 report.txt
Terminal window
ls -l report.txt
Captured output
-rw-r--r-- 1 learner learner 12 Nov 14 15:53 report.txt

Read the owner and group names as well as the bits. Dates, IDs, and some metadata can differ on your VM; the prepared permission fields are what you compare here.

Use a symbolic mode to state the desired permissions by class:

Terminal window
chmod u=rw,g=r,o= report.txt
Terminal window
ls -l report.txt
Captured output
-rw-r----- 1 learner learner 12 Nov 14 15:53 report.txt

u selects the owning user, g the owning group, and o everyone else. Each = replaces that class’s ordinary permissions. o= has no letters after it, so it clears all three other bits. The result keeps owner read/write, group read, and no other access.

The operators from B11.3 also work here: + adds selected bits and - removes them while leaving the other ordinary bits alone. Use explicit classes so you can see whose permissions you are changing. chmod changes the mode; it does not change the owning account or group.

A numeric mode uses base-eight, or octal, digits. Add these values within each class:

Bit Value
Read 4
Write 2
Execute/search 1

Three digits specify owner, group, and other, in that order. Owner read/write is 4 + 2 = 6; group read is 4; no bits is 0. Thus 640 expresses the same ordinary bits as the symbolic mode above.

Predict first: does changing 640 to 600 remove the owner’s ability to read?

Terminal window
chmod 600 report.txt
ls -l report.txt
Run it, then compare with your guess
Captured output
-rw------- 1 learner learner 12 Nov 14 15:53 report.txt

No. Only the middle digit changed: group read was removed. Owner rw- remains.

Restore the group-read bit with the complete numeric mode, then verify it:

Terminal window
chmod 640 report.txt
Terminal window
ls -l report.txt
Captured output
-rw-r----- 1 learner learner 12 Nov 14 15:53 report.txt

Numeric modes describe the full set of ordinary permissions. Symbolic additions or removals are useful when you intend to change only selected bits. Neither form changes the file’s text.

The file still belongs to group learner. Change only its owning group:

Terminal window
sudo chgrp team report.txt
Terminal window
ls -l report.txt
Captured output
-rw-r----- 1 learner team 12 Nov 14 15:53 report.txt

Compare this with the preceding listing: the group changed to team; the owner and rw-r----- stayed the same. An ordinary owner can change a file to a group available to their process. This running shell does not yet have team, so this exercise uses sudo for the group change.

Run the same read as the owner, a teammate, and an unrelated account:

Terminal window
cat report.txt
Captured output
Team review
Terminal window
sudo -u sam cat report.txt
Captured output
Team review
Terminal window
sudo -u nobody cat report.txt
Captured output
cat: report.txt: Permission denied

sudo -u sam runs this command as sam, not as root. The teammate succeeds through group team; nobody falls into the other class and fails. These commands inherit the existing practice working directory. They test access there; they do not grant traversal through your home directory from elsewhere.

Three access classes for the team report At mode 640, learner owns the report, sam reads through group team, and nobody has no permitted file operation. report.txt: learner / team, 640 Owner learner: read and write Group member sam: read Other account nobody: denied
Three access classes for the team report At mode 640, learner owns the report, sam reads through group team, and nobody has no permitted file operation. report.txt: learner / team, 640 Owner learner: read and write Group member sam: read Other account nobody: denied
Simplified model. For the learner-owned team report at mode 640, learner can read and write, sam can read through team, and nobody is denied.

In words, each account uses one applicable class. This model assumes the inherited practice working directory is accessible, with no additional ACL rules or privileged bypass.

Access
learner@rootvolt:~/lab$ cd ~/lab/b11/changeslearner@rootvolt:~/lab/b11/changes$ ls -l report.txt-rw-r--r-- 1 learner learner 12 Nov 14 15:53 report.txtlearner@rootvolt:~/lab/b11/changes$ chmod u=rw,g=r,o= report.txtlearner@rootvolt:~/lab/b11/changes$ ls -l report.txt-rw-r----- 1 learner learner 12 Nov 14 15:53 report.txtlearner@rootvolt:~/lab/b11/changes$ sudo chgrp team report.txt[sudo] password for learner: learner@rootvolt:~/lab/b11/changes$ ls -l report.txt-rw-r----- 1 learner team 12 Nov 14 15:53 report.txtlearner@rootvolt:~/lab/b11/changes$ sudo -u sam cat report.txtTeam reviewlearner@rootvolt:~/lab/b11/changes$ sudo -u nobody cat report.txtcat: report.txt: Permission deniedlearner@rootvolt:~/lab/b11/changes$ cat report.txtTeam reviewlearner@rootvolt:~/lab/b11/changes$ 

Files ~/lab/b11/changes

  • ~
    • lab/b11/changes/cwd
      • report.txtargument-rw-r-----

Step-by-step replay of a verified session · Recorded on Ubuntu 24.04.5 LTS, GNU Bash 5.2.21. Restrict the report, assign group team, and compare a teammate's successful read with an unrelated account's denial.
Steps (27)
  1. Type cd ~/lab/b11/changes
  2. Press Enter
  3. Type ls -l report.txt
  4. Press Enter
  5. Output: -rw-r--r-- 1 learner learner 12 Nov 14 15:53 report.txt
  6. Type chmod u=rw,g=r,o= report.txt
  7. Press Enter
  8. Type ls -l report.txt
  9. Press Enter
  10. Output: -rw-r----- 1 learner learner 12 Nov 14 15:53 report.txt
  11. Type sudo chgrp team report.txt
  12. Press Enter
  13. Output: [sudo] password for learner:
  14. Type the password (the terminal shows nothing)
  15. Press Enter — Type the password (not shown) and press Enter
  16. Type ls -l report.txt
  17. Press Enter
  18. Output: -rw-r----- 1 learner team 12 Nov 14 15:53 report.txt
  19. Type sudo -u sam cat report.txt
  20. Press Enter
  21. Output: Team review
  22. Type sudo -u nobody cat report.txt
  23. Press Enter
  24. Output: cat: report.txt: Permission denied
  25. Type cat report.txt
  26. Press Enter
  27. Output: Team review

The Files panel follows permission changes. Owning names are verified in the terminal listings; the panel does not display ownership or simulate another account’s access.

Transfer ownership without changing the mode

Section titled “Transfer ownership without changing the mode”

The preceding listing is your before-state. Transfer the file to sam while retaining group team:

Terminal window
sudo chown sam:team report.txt
Terminal window
ls -l report.txt
Captured output
-rw-r----- 1 sam team 12 Nov 14 15:53 report.txt

chown user:group sets both owning identities. Changing the owning user requires privilege on this system, even when you originally owned the file. The mode still grants owner read/write and group read.

Predict first: can the original learner shell still read it, merely because its configured account was added to team?

Terminal window
cat report.txt
Run it, then compare with your guess
Captured output
cat: report.txt: Permission denied

No. This shell no longer matches the owner and still lacks the supplementary group. It uses the other field, which grants nothing.

Start a fresh command as learner and inspect its groups before reading:

Terminal window
sudo -u learner id
Captured output
uid=1001(learner) gid=1001(learner) groups=1001(learner),27(sudo),1003(team)
Terminal window
sudo -u learner cat report.txt
Captured output
Team review

This process obtains the configured team membership. The original shell’s groups remain unchanged. On your VM, a fresh login normally obtains the updated list; do not assume every existing terminal changed with the account database.

Restore ownership for the challenge, verifying the transition from the preceding sam-owned state:

Terminal window
sudo chown learner:team report.txt
Terminal window
ls -l report.txt
Captured output
-rw-r----- 1 learner team 12 Nov 14 15:53 report.txt

Reading the other field when a group match applies. The successful sam read used group r--. Permissions from different classes are not added together.

Changing permissions when membership is stale. Compare the named-account lookup with the actual process identity before broadening access. The learner failure above came from its unchanged running group list.

Treating a successful chmod as complete verification. Inspect the resulting bits and test the intended operation as the intended account. A valid mode still cannot repair a blocked parent path from B11.3.

Goal: Allow the existing owning group to write the report too, keeping the owner unchanged and other access absent. Add only the necessary bit, then verify the result.

Hint

Use the symbolic addition operator for the group class. Compare with the before-state rw-r-----.

Solution
Terminal window
chmod g+w report.txt
Terminal window
ls -l report.txt
Captured output
-rw-rw---- 1 learner team 12 Nov 14 15:53 report.txt

The result is rw-rw----, equivalent to ordinary mode 660. Group write permits modifying contents; it does not grant execution.

First return the practice file to your normal owning identities and inspect the result:

Terminal window
sudo chown learner:learner report.txt
Terminal window
ls -l report.txt
Captured output
-rw-rw---- 1 learner learner 12 Nov 14 15:53 report.txt
Terminal window
cd ~/lab/b11
ls -AR changes
Terminal window
rm -r ~/lab/b11/changes
sudo userdel -r sam
sudo groupdel team
getent passwd sam
getent group team

getent queries the configured account/group databases. Both final lookups print no entries and return status 2 in the verified reset. userdel reports that sam’s mail spool is absent in this container; the account and home are removed. Repeating setup starts from those absent names. Do not remove unrelated accounts with these commands.

  • Symbolic modes select classes and add, remove, or replace permission bits.
  • Numeric modes assign owner, group, and other bits using values 4, 2, and 1.
  • chgrp changes the owning group; privileged chown changes the owning user, optionally with its group.
  • Verify metadata and actual access, using the group list of the process doing the work.

Next, Using sudo and su separates delegated commands, target-account authentication, and the shell opening a redirection.