How to use the chown command to change permissions in Linux

  • Last updated: Nov 28, 2024
  • Views: 31
  • Author: Admin

Changing file and directory permissions is one of the key tasks of a Linux system administrator. The chown command provides a simple and effective way to manage owner and group permissions for files and folders.

In this article, we will take a detailed look at how the chown command works, what parameters it supports, and how to use it correctly to configure access in various situations. With this knowledge, you will be able to organize more secure and flexible work with files on your system.

 

Syntax:

chown [OPTION] [USER][:[GROUP]] FILE

  • USER - Username of the new owner.
  • GROUP - Group name.
  • FILE - The name of one or more files, directories.

In the USER field, you need to specify the user whom we will make the owner of the file or directory. The GROUP field can be omitted, but if you specify it, all users of this group will be owners. FILE(s) is the name of the file or directory.

 

All main options [OPTIONS]:

  • -c - Detailed output of all changes performed.
  • -R  - Recursively process all subdirectories.
  • -L - Follow all symbolic links to directories.

 

Let's say we have a directory engineer and another app is created in it and it has root as the default owner.

chown


 

Now let's assign the owner of this directory to the postgres user, for this we will use the command:

$. chown postgres /inzhener

chown

As we can see in the screenshot, previously we had the owner root, but after the change it became postgres.


 

In this example, let's make not only the postgres user the owner, but also the postgres group, to do this, run:

$. chown postgres:postgres /inzhener

chown

And now we see that the owner of the directory is not only the postgres user, but also the postgres group.


 

In the following example, we will make the assignments of the owner of the postgres directory and the postgres group recursively, which means that we assign the new owner postgres to all nested directories.

$. chown -R postgres:postgres /inzhener


 

In summary, the chown command is a powerful tool for managing file owners and groups in Linux. Using this command correctly helps to configure access to files and folders, increasing security and ease of use in the system. We have analyzed the main commands, parameters and examples of using chown, which will help you effectively solve rights management tasks. Having mastered this utility, you can easily maintain order and security in your file system.

 

SIMILAR ARTICLES