Signup/Sign In
MAY 16, 2023

How to change Ownership and Permissions in Linux?

Technology #macOSX#linux#chown

    Chown commands looks at managing ownership and permission of files in the Linux operating system, this one of the most critical aspects of an administrator's job

    In this article, we will discuss different tools that allow us to do it, and then we will look at setting quotas where we can actually restrict users to a certain amount of space on the file system ownership and how we can change ownership.

    The key point to understand is that every file on a Linux system is owned by two entities user and the group ownership, that's because on a Red Hat-based system they use the user private group scheme, so when we create a user, for instance, student, a group is created along with that user and the only member of that group is the user account itself. Anytime a student or any account on the system including root creates a file and folder, by default that account becomes the owner of that file or folder.

    There are two commands that we can use to change the ownership of files and folders. The change group (chgrp) command or the change owner (chown) command.

    Open your terminal and here we can see our group membership by typing the ID command.

    Ownership and Permissions

    We can change the following three kinds of ownership permissions.

    • Read Permission
    • Write Permission
    • Execute Permission

    Types of file Permissions on Linux.

    There are three kinds of File permission on Linux.

    • User
    • Group
    • Other

    Generally, we use the command ls-l to view the permissions of the file.

    Using chown command to change the Ownership.

    If you want to change the ownership of the file, we used the command called chown.

    Syntax

    Let’s look at the syntax of the chown command.

    $ chown [OPTION]… –reference=RFILE FILE…

    Here the reference is the file permission that the file contains and the refiling is the file permission to which to want to convert.

    $ chown [OPTION]… [OWNER][:[GROUP]] FILE…

    Example

    $ chown owner_name file_name
    
    $ chown admin stn1.txt

    If the user is the username of the file system and the admin is the other user of the same system. Now we can change the ownership to root using the following command.

    $ sudo chown root stn1.txt

    Options

    The following are the various options that we can use with the chown command

    -c

    $ chown -c admin stn1.txt

    By using this option, the system reports the user if we made any changes to the file stn1.txt

    -v

    $ chown -v admin stn1.txt

    The–v displays of verbose information of the file stn1.txt

    -f

    $ chown -f admin stn1.txt

    If you want to forcefully, change the ownership, ignoring the errors it can raise, we can simply use–f along with the chown command.

    Change group ownership

    Here, if we want to change the group ownership, let’s assume stn1.txt is a file that contains group ownership. Now we use the following command.

    $ chown :group1  stn1.txt

    Now, the group permissions of the file stn1.txt are changed to group1 from root.

    Change the owner and group ownership

    Now taking admin as user and group1 as a group, we use the command

    $ chown admin:group1 studytn1

    Change the owner from particular ownership only

    Now, wanted to make only admin as the owner for all root files, we use the command.

    $ chown --from=admin root studytn1

    Change group from a particular group

    $ chown --from=:group1 root studytn1

    Here, the group of studytn1 is changed to root.

    Copy ownership of one file to another

    $ chown --reference=studytn1 studytn12

    Here we copied permissions from studytn1 to studytn12

    Change ownership of multiple files

    $ chown admin:group studytn12 studytn13

    Conclusion

    The article gives you a brief about one of the important commands on Linux called chown, how to use this command, and what is the syntax of the command.

    Hope you like the article.

    IF YOU LIKE IT, THEN SHARE IT
    Advertisement

    RELATED POSTS