Technology Encyclopedia Home >How to change file system permissions and ownership in Linux?

How to change file system permissions and ownership in Linux?

In Linux, you can change file system permissions and ownership using the chmod and chown commands, respectively.

Changing File Permissions with chmod

The chmod command modifies the read (r), write (w), and execute (x) permissions for the owner, group, and others. Permissions can be set using either symbolic notation or numeric (octal) notation.

Symbolic Notation Example:

chmod u+x script.sh  # Add execute permission for the owner
chmod g-w file.txt   # Remove write permission for the group
chmod o=r document.pdf # Set read-only permission for others
  • u = user (owner), g = group, o = others, a = all (default).
  • + adds a permission, - removes it, = sets it explicitly.

Numeric (Octal) Notation Example:

chmod 755 script.sh  # Owner: rwx (7), Group: r-x (5), Others: r-x (5)
chmod 644 file.txt   # Owner: rw- (6), Group: r-- (4), Others: r-- (4)
  • Each digit represents permissions for owner, group, and others (in that order).
  • Values are calculated as: r=4, w=2, x=1 (sum for combined permissions).

Changing File Ownership with chown

The chown command changes the owner and/or group of a file or directory.

Basic Syntax:

chown user:group filename  # Change both owner and group
chown user filename        # Change only the owner
chown :group filename      # Change only the group

Example:

chown alice:developers script.sh  # Set owner to 'alice' and group to 'developers'
chown root /etc/config.conf       # Set owner to 'root' (group remains unchanged)

Recursive Permission/Ownership Changes

To apply changes to all files and subdirectories within a directory, use the -R flag:

chmod -R 755 /var/www/html  # Recursively set permissions for a web directory
chown -R user:group /data   # Recursively change ownership for a data directory

Cloud Storage Context (e.g., Object Storage)

If you're managing permissions for files in a cloud storage service (like object storage), the process differs. For example, in Tencent Cloud COS (Cloud Object Storage), permissions are managed via Access Control Lists (ACLs), bucket policies, or IAM roles rather than chmod/chown. Use the Tencent Cloud console or CLI to configure these settings.

For local Linux systems, chmod and chown are the standard tools for managing file permissions and ownership.