Linux

Managing File Ownership and Permissions in Linux: A Detailed Guide

This guide covers the basics of managing file ownership and permissions in Linux. You'll learn how to use the chown, chgrp, and chmod commands to configure security and file access.

Updated at February 15, 2026
10-15 minutes
Medium
FixPedia Team
Применимо к:Ubuntu 20.04+Debian 10+CentOS 7+All modern Linux distributions

Introduction / Why This Matters

In Linux, every file and directory has an owner (user) and a group, as well as a set of access permissions (read, write, execute). These attributes determine who can do what with the file. Managing them is critical for system security, team collaboration, and proper application operation. For example, a web server should only have access to necessary files, and scripts need execute permissions. This guide will help you confidently change ownership, group, and permissions using standard commands.

Requirements / Preparation

Before you begin, ensure that:

  • You have access to a Linux terminal (locally or via SSH).
  • You know basic navigation commands (cd, ls).
  • To change other users' files, administrator privileges (sudo) are required. If you are working with your own files, sudo is not needed.
  • The standard utilities chown, chgrp, chmod are installed—they are included by default in all distributions.
  • You know the username or group to which you want to change the attributes. You can check existing users in /etc/passwd, groups in /etc/group.

Step 1: Checking Current Permissions

First, you need to understand how permissions are currently set. Use the ls -l command for a detailed file list.

ls -l файл

Example output:

-rw-r--r-- 1 alice developers 1024 Feb 15 10:00 example.txt

Here:

  • -rw-r--r-- — permissions: owner (alice) can read and write, group (developers) can only read, others can only read.
  • alice — file owner.
  • developers — file group.

For a directory, permissions may include x (execute/access).

💡 Tip: Use ls -ld каталог to see permissions on the directory itself, not its contents.

Step 2: Changing File Owner (chown)

The chown command changes the owner of a file or directory. Syntax:

sudo chown [новый_владелец] файл

Example: Change owner of example.txt to bob:

sudo chown bob example.txt

Recursive Change

To change the owner for all files inside a directory, add the -R flag:

sudo chown -R bob /путь/к/каталогу

⚠️ Important: Be careful with recursive changes in system directories (e.g., /etc), as this can disrupt system operation.

Changing Owner and Group Simultaneously

Use a colon to specify the group:

sudo chown bob:developers example.txt

This changes the owner to bob and the group to developers. If you specify only the group (e.g., :developers), the owner remains unchanged.

Step 3: Changing File Group (chgrp)

If you only need to change the group, use chgrp:

sudo chgrp новая_группа файл

Example:

sudo chgrp marketing example.txt

Alternatively, via chown with a colon (as shown above). Recursion with -R:

sudo chgrp -R marketing /путь/к/каталогу

Step 4: Setting Permissions (chmod)

Permissions are managed for three categories: owner (u), group (g), others (o). Each category can have permissions: read (r), write (w), execute (x).

Symbolic Mode

The most intuitive method. Examples:

  • Add execute permission for the owner: chmod u+x скрипт.sh
  • Remove write permission from group and others: chmod go-w файл
  • Give full access to everyone (caution!): chmod a=rwx файл

Numeric (Octal) Mode

Permissions are set with three digits (or four, including special bits). Each digit is a sum of values: r=4, w=2, x=1.

  • 755 — owner: rwx (4+2+1=7), group and others: rx (4+1=5).
  • 644 — owner: rw- (4+2=6), group and others: r-- (4).

Example:

chmod 755 скрипт.sh  # Gives owner full access, group and others read and execute.

Recursive Change

chmod -R 755 /путь/к/каталогу

💡 Tip: For scripts, chmod +x файл is often sufficient, equivalent to chmod a+x файл.

Step 5: Practical Examples and Tips

Example 1: Web Server Setup

Website files owner: www-data, group: developers, permissions: owner read/write, group and others read-only.

sudo chown -R www-data:developers /var/www/html
sudo chmod -R 755 /var/www/html
sudo chmod -R 644 /var/www/html/*.html  # For HTML files: owner read/write, others read-only.

Example 2: Team Project Collaboration

All files in /project should belong to group team, with write permissions for group members.

sudo chown -R :team /project
sudo chmod -R 775 /project  # rwx for owner and group, rx for others.

Example 3: Protecting a Confidential File

Only the owner can read and write.

chmod 600 ~/.ssh/id_rsa

::in-article-ad

::

Step 6: Verifying the Result

After making changes, always verify that everything was applied correctly:

ls -l файл

Ensure the new owner, group, and permissions are displayed. For a directory with recursive changes, check several nested files.

If permissions did not change, possible reasons:

  • You did not use sudo for other users' files.
  • The specified user or group does not exist (check via id пользователь or getent группа).
  • The file is on a mounted filesystem with the noacl option (e.g., some FAT/NTFS), where Linux permissions are not supported.

Common Issues

"Operation not permitted" Error

Occurs if:

  • You try to change the owner to another user without sudo.
  • The file is on a filesystem that does not support owner changes (e.g., mounted with nosuid or noacl). Solution: Use sudo or check mount options (mount).

"No such file or directory" with chown/chgrp

The specified user or group does not exist. Solution: Create the user/group (sudo useradd имя, sudo groupadd имя) or specify correct ones.

Incorrect Permissions After chmod

You might have confused the numeric mode. For example, chmod 777 gives full access to everyone—this is dangerous. Solution: Use the minimal necessary permissions. For scripts—755 (owner: rwx, group and others: rx). For configs—644 or 600.

By default, chown -R and chmod -R follow symbolic links. To change the link itself rather than the target file, use -h (where supported). Be careful not to break the system.

Permissions Not Applied to New Files

New files inherit the group from the parent directory if the setgid bit is set. To ensure a consistent group, set setgid on the directory:

sudo chmod g+s каталог

Now new files in this directory will have the directory's group.

Questions and Answers

Q: How do I change both owner and group at the same time?
A: sudo chown пользователь:группа файл. Example: sudo chown alice:devs file.txt.

Q: What if the chown command doesn't work?
A: Check sudo privileges, existence of user/group, and filesystem. Use id to verify the user.

Q: How do I give execute permission to a script?
A: chmod +x скрипт.sh or chmod 755 скрипт.sh.

Q: What's the difference between chown and chgrp?
A: chown changes the owner (and optionally the group), chgrp changes only the group. For the group, you can also use chown :группа файл.

F.A.Q.

What to do if the chown command doesn't work?
How to grant execute permissions to a script?
What is the difference between chown and chgrp?

Hints

Check current file permissions
Change file owner
Change file group
Set access permissions
Verify changes
FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community