Change a File's Owner

Change a File's Owner

The teacher prepared a report, but the assistant is now responsible for maintaining it. File ownership records which user owns the entry. chown can change that owning identity when the operation is authorized. It does not mean 'copy the report into the person's home' or 'give everyone write access.'

Ownership and mode work together but describe different things. Let's change the user owner of a disposable report and read the owner field afterward. Keep administrative authority separate from the permission bits on the file itself.

What you’ll learn

  • Change a file’s owning user with chown.
  • Verify the owner and understand the privilege needed to change it.

Ownership names the user responsible for a file

  1. Before

    The report belongs to its current owning user.

    marks.txt: current owner
  2. Change

    An authorized chown operation selects the new owning user.

    school-assistant
  3. Verify

    ls displays the new owner; ownership changes may also affect special bits.

    owner field changed
Use ownership commands for identity metadata and mode commands for permission bits.

Assign the report to the school assistant

Prepare the example

In the disposable VM, create the practice assistant account first and confirm it resolves. The block creates marks.txt if missing, then uses an authorized administrative change. Do not apply the exercise to system files or transfer ownership of work you still need to manage without a plan.

Bash · Linux terminal

touch marks.txt
sudo chown school-assistant marks.txt
ls -l marks.txt

Expected behavior; machine-dependent details

The owner field reflects school-assistant when the account exists.

touch marks.txt prepares the file. sudo chown school-assistant marks.txt selects the new owning user by name, and ls -l displays that owner field afterward. The filename and report contents are not renamed or rewritten by this request.

Changing ownership is not equivalent to setting a mode. The ordinary bits determine access in the context of the updated owner and group, and ownership changes can affect special bits under system rules. Verify the full relevant metadata instead of assuming only one displayed field could matter. An ordinary user does not have a general right to give arbitrary files to any other user.

User ownership, combined ownership and recursive scope

Every Linux file has an owning user and an owning group. The chown command changes one or both of those ownership fields.

‍ Example Scenario

Imagine you’re an admin and you’ve just created a file, but now you want to assign it to another user named john. Here’s how you do it.

sudo chown john file.txt

This command changes the owner of file.txt to the user john.

Let’s walk through it step by step.


Step 1: Check Current Ownership

We’ll use the ls -l command to check who owns the file.

ls -l file.txt
-rw-r--r-- 1 root root 0 Jul 2 11:00 file.txt

Here, the file is owned by root (user and group).


Step 2: Change Ownership to Another User

sudo chown john file.txt

This changes the user owner to john, but keeps the group as it is.

Verify again:

ls -l file.txt
-rw-r--r-- 1 john root 0 Jul 2 11:00 file.txt

Step 3: Change Both User and Group Ownership

Let’s say you also want to change the group to john’s group:

sudo chown john:john file.txt

That’s user:group format.

-rw-r--r-- 1 john john 0 Jul 2 11:00 file.txt

Perfect!


Bonus: Change Ownership Recursively

What if you want to change ownership for a folder and everything inside it?

sudo chown -R john:john my_folder/

The -R flag makes the operation recursive, changing ownership for all subfolders and files too.


Assign file ownership with chown

  • chown user file — change file owner
  • chown user:group file — change owner and group
  • chown -R user:group folder/ — recursive change

Practice it, and you’ll get comfortable managing permissions confidently!

Try it, then check the worked answer

Your task: Which operation changes ownership rather than mode?

In the disposable VM, create the practice assistant account first and confirm it resolves. The block creates marks.txt if missing, then uses an authorized administrative change. Do not apply the exercise to system files or transfer ownership of work you still need to manage without a plan.

Bash · complete example for this question

touch marks.txt
sudo chown school-assistant marks.txt
ls -l marks.txt

Expected behavior; machine-dependent details

The owner field reflects school-assistant when the account exists.

Worked answer

chown school-assistant marks.txt

Choose chown for the owning user. chmod 640 changes permissions, and chgrp changes the owning group. The task is about which identity owns the report, so select the operation that updates that part of its metadata.

Check your decision

Which operation changes ownership rather than mode?
Choose one answer. You can try again.

Answer and explanation

chown school-assistant marks.txt

Choose chown for the owning user. chmod 640 changes permissions, and chgrp changes the owning group. The task is about which identity owns the report, so select the operation that updates that part of its metadata.

Change the owner separately from the permission mode

Use ownership commands for identity metadata and mode commands for permission bits. Confirm the target account, the file and the authority for the change. Inspect the owner and relevant permissions afterward, because responsibility and permitted operations both affect the final result.

Reaching the recap and completing the quizzes are separate milestones.

    Next lesson: Change a File's Group →