RedTeam Nexus Labs
Module 04 · Lesson 04 // Permissions

chown

Permissions · Linux

Freereading · 10 min
On this page
LESSON

Overview

chown ("change owner") sets which user and group own a file. Together with chmod, it completes control over file access. This lesson explains changing ownership and why it requires care and privilege.

Learning objectives

  • Use chown to change user and/or group ownership.
  • Explain why changing ownership generally requires root.
  • Combine ownership and permissions correctly.

Core concept

chown changes a file's owner and/or group:

  • chown alice file — set the user owner to alice.
  • chown alice:devs file — set user owner alice and group owner devs.
  • chown :devs file — change only the group (or use chgrp devs file).
  • chown -R alice:devs dir — apply recursively to a directory tree.

Because giving away or reassigning ownership can bypass access controls, changing a file's user owner typically requires root privileges.

How it works

Ownership plus permissions together decide access, so chown and chmod are used in tandem: first set the right owner/group, then the right permission bits. Recursive chown -R is powerful — it retags an entire tree — so it must target the correct directory, as a mistaken recursive change (e.g. on system directories) can break a system. Regular users generally cannot hand their files to another user (which could be abused), so that action is reserved for root.

Practical example

$ sudo chown www-data:www-data /var/www/site       # hand a web dir to the web service account
$ sudo chown -R alice:devs /home/alice/project      # retag a whole project tree to alice:devs

The first gives the web server's files to the www-data service account so the service can manage them under least privilege; the second recursively assigns a project directory to alice and the devs group. Both use sudo because changing user ownership needs elevated rights.

Cybersecurity relevance

Ownership is a control boundary, so chown is security-relevant. Assigning files to the appropriate service account (rather than root) supports least privilege; conversely, wrong ownership can grant unintended control. Careless recursive chown on system paths is a real hazard that can render a system unbootable or insecure. During hardening, ensuring sensitive files are owned by the correct, minimal-privilege account is as important as their permission bits.

Common mistakes

  • Running recursive chown -R on the wrong (or a system) directory, potentially breaking the system.
  • Expecting a regular user to change a file's user owner — that normally requires root.
  • Setting permissions without fixing ownership, leaving the wrong account in control.

Key takeaways

  • chown sets a file's user and/or group owner (chown user:group file), with -R for recursive changes.
  • Changing the user owner generally requires root, since reassigning ownership can bypass access controls.
  • Use chown with chmod to place files under the correct, least-privilege owner; careless recursive changes are dangerous.

Check your understanding

  • Why does changing a file's user owner typically require root privileges?
  • What is the risk of running chown -R against the wrong directory?
FINISH THIS LESSON

Sign in to save your progress.