Advance

Tutorial use Chown on Ubuntu and Debian

Tutorial use Chown on Ubuntu and Debian
0
(0)

With Linux, each file belongs to a specific user. Although files support group licenses, the purpose of ownership is to ensure that only those who actually have access to the file can read, write, or execute it. Without ownership, these cases are generally out of bounds. In this article, we are going to teach you How to use Chown on Ubuntu and Debian. You can visit the packages available in Eldernode if you wish to purchase an Ubuntu VPS server.

How to Use Chown on Ubuntu and Debian [Complete]

Recommended Article: How to check which Apache Modules are Enabled/Loaded in Linux

Introduction to Chown Command

The Chown command stands for change owner. This command is used in Unix and Unix-like operating systems to change the owner of file system files and directories. Unprivileged users who wish to change the group membership of a file that they own may use chgrp.

Ownership of any file on the system may be changed only by one superuser. The user can not transfer ownership of a file, even if the user owns it. Similarly, only one member of a group can change the file group ID to that group.

The Chown command has also been ported to IBM I and allows you to change the ownership of the user and/or filegroup, list, or symbolic link.

In Linux, all files are associated with one owner and one group and have access rights for the file owner, group members, and others. In this tutorial, you will learn to use the Chown command to change the owner of the file and group information. Please stay tuned for the rest of this article.

Using Chown on Ubuntu and Debian

In this section, we want to teach you How to Use Chown on Ubuntu and Debian. To do this, just follow the steps below. In this tutorial, we will learn how to use the Chown command to change the owner and group of files and directories.

Before starting syntax, use this command as follows:

chown [OPTIONS] USER[:GROUP] FILE(s)

USER can be in the form of a username or UID, which will be the new Owner of the FILE file.

GROUP can be in the form of a group name or GID, which will be the new Group FILE file.

How to Change File Owner Using Chown on Ubuntu and Debian

You can use the following command to change the owner of a file. Note that you must replace the USER with the username you want for the new Owner:

chown USER FILE

For example, in the following command, the Owner sets the eldernode.txt file on the abc user:

chown abc eldernode.txt

You can also split several files between filenames to change the Owner:

chown abc file1 file2

Note: In the above commands, if you put the directory name instead of the file name, the Owner directory will change.

How to change Owner and Group files

With the following command, it is possible to change the Owner and Group of a file or directory at the same time:

chown USER:GROUP FILE

You can only change the group as follows:

chown :GROUP FILE

To change the Owner or Group of all files in a directory, you can use -R in the following command. It should be noted that you must use the directory name instead of the file name:

chown -R USER:GROUP DIRECTORY

Change Symbolic Links Ownership using Chown

Now in this section, we want to discuss how to Change Symbolic Links Ownership using Chown. Note that when the return option is not used, the Chown command changes the group ownership of the files referenced by the symlinks, not the symbolic links themselves.

For example, if you try to change the owner and group of the symbolic link symlink1 pointing to /var/www/file1, Chown changes the ownership of the file or the symlink directory:

chown www-data: symlink1

Note that the “cannot dereference‘ symlink1 ‘: Permission denied “error occurs because symlinks are protected by default in most Linux distributions. Also, you can not work on the desired files. This option is specified in /proc/sys/fs/protected_symlinks.

1 means active and

0 means inactive.

Note: We recommend that you do not disable syml link protection.

You can use the following command to change the group ownership of the syml link:

chown -h www-data symlink1

How to Recursively Change the File Ownership

After learning the previous steps, we now intend to teach you How to Recursively Change File Ownership. You can use the following command to recursively operate on all files and directories listed:

chown -R USER:GROUP DIRECTORY

As you can see in the following example, the ownership of all files and subdirectories in the /var/www directory is changed to a new owner and group called www-data:

chown -R www-data: /var/www

If the list contains symbolic links, you can use the following command:

chown -hR www-data: /var/www

How to Use a Reference File with Chown on Linux Ubuntu | Debian

In the final section, we will teach you how to Use a Reference File with Chown. Note that the following command allows you to change the ownership of the user and the group of files given, such as the specified reference file (ref_file):

chown --reference=REF_FILE FILE

Here is an example. You can assign file1 user and group ownership to file2 using the following command:

chown --reference=file1 file2
Recommended Article: How to check Linux kernel version on VPS

Conclusion

As you learned in this tutorial, Chown is a Linux/UNIX command-line tool for changing user ownership and/or filegroups. In this article, we tried to introduce you to Chown first. Then we taught you how to use the Chown command using different sections.

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

    Leave Your Comment

    Your email address will not be published.

    We are by your side every step of the way

    Think about developing your online business; We will protect it compassionately

    We are by your side every step of the way

    +8595670151

    7 days a week, 24 hours a day