Definition and How to Use Chown

Definition and How to Use Chown

Title: Definition and How to Use Chown
For You. Get More Information from our site @iwanrj.com free.

On Linux OS, each file is associated with an ownership and owner group. The Linux chown command stands for “change owner.” This command is used on Unix-like systems by the superuser. In this article, we will cover what the Chown command is for and how to use it.

With the chown option, you can change the ownership of files, directories, and links. If a regular user wants to change a file, the superuser can use the chown command to change the ownership of the file and give it access rights.

Chown definition

Chown is a command on Unix and Linux operating systems that is used to change the ownership of a file or directory. By using the chown command, you can change the ownership of a file or directory to another user with the appropriate access rights.

For example, when a user wants to grant another user certain access rights to a file or directory, he can use the chown command to change the ownership of that file or directory to the user to whom he will grant access.

The chown command has a simple and easy to understand syntax. However, keep in mind that you have to be careful when using the chown command. If there is an error in granting file permissions, it can cause access failures to files or directories and can cause security holes in the system.

How to Use Chmod and Chown

The chown and chmod commands can be run using the Terminal on Linux. Both of these commands can only be executed by the user root or super user. You can see the ownership and user owner of a file using the command ls -l or ll.

The results will be displayed in the following format:

drwxrwxr-x 2 Antvps Antvps 4090 Dec 3 07:16 folderC

drwxrwxr-xThis section displays the permissions (access rights) of a file or folder. The d in front means that it is a directory. If the file doesn’t have a prefix, for example like this -rw-rwx-wx

rwx is the type of permission that applies to the file or folder.

The initial “rwx” indicates access rights for user. The second “rwx” shows the permissions for group owner, and rx denotes the access rights for the user type others.

2Number of hard links. Usually a hard link is an additional name for a file.
antvpsRepresents the owner’s username information of the file or folder.
antvpsIs the group name information of a file or folder.
4096Displays file size in bytes. You can use the -h option to display the size in another way
Dec 3 07:16The last modified date of the file.
FolderCFile or folder name.

View Proprietary Information

First of all, login to the VPS using SSH. .In case you forgot, please check out the tutorial which covers everything there is to know. .

Before using the Linux chown command, you need to confirm the specified user and group information. This information can be obtained using CD and navigate to the required directory.

For example, the file path is /tmp/TestUnix. To access it, use the command:

Here you can sort the files in the directory by using the following command :

In this tutorial, we created a file named chownSample. txt inside the directory. The output of the above command will be like this:

-rw-r--r-- 1 root root 0 Feb 20 17:35 chownSample.txt

Part -rw-r–r– represents file permissions. The first root refers to the ownership information and the second root represents the group information. In the above example, chownSample. txt has ownership root and that root belongs to the root group.

Chown for Files

To change the ownership of a file, the basic command format is:

On the same file, ie chownSample. txtwe will change the ownership from root to another user with the name Whales. An example of the command is as below:

chown whales chownSample.txt

To verify the ownership change, use the command ls -l. The command will give the following output:

-rw-r--r-- 1 whales root 0 Feb 20 17:45 chownSample.txt

The command can be modified to change the group. The basic format for changing ownership and group is:

chown user[:group] filename(s)

If you want to change the file ownership chownSample. text the same to the Whales owner with the aquatic group, then use the command:

chown whales:aquatic chownSample.txt

To verify ownership and group, use ls -l. The output of this command will look something like:

-rw-r--r-- 1 whales aquatic 0 Feb 20 17:50 chownSample.txt

If only the group is changed, skip the ownership section. For example, you can type the following command at the command line :

chown :aquatic chownSample.txt

Chown has a function similar to chgrp when owner information is not available. This command can be used with several options.

The generic structure of the chown command with several options looks something like this:

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

Chown for Directory

Chown can also be applied to directories. This chown contains only files, or only directories, or a combination of both.

Let’s say we have a directory named TestUnix. To see its permissions, we use the command ls-l. An example of the output is as follows:

drwxr-xr-x 2 root root 4096 Feb 20 17:35 TestUnix

First part drwxr-xr-x refers to the folder permissions. The first root is the information about the ownership and the second root refers to the group information. In this example, TestUnix has an ownership root and a group root.

Just like other files, the ownership and group of directories can also be changed. The command is like this:

To change the group only, use :

To change the ownership and group of files, use:

chown whales:aquatic /TestUnix

The same command can also be used to provide multiple files and directories. Here’s an example of the command format:

chown [OPTIONS] [USER][:GROUP] file1 file2

Example command after the format is filled in correctly:

chown whales:aquatic /tmp/TestUnix/chownSample.txt /tmp/TestUnix

Linux chown command can be used on symbolic links or soft links. Symbolic links are links that point to other files or folders. The in command is used to create soft links. for files chownSamole. txtsymbolic links can be created using the command below:

ln -s chownSample.txt symlink

To verify ownership and group information, use the command ls -l. This command will produce the following output:

-rw-r--r-- 1 root root 0 Feb 19 22:01 chownSample.txt
lrwxr-xr-x 1 root root 5 Feb 19 7 22:01 symlink -> chownSample.txt

There are two entries available. One for physical files and the other for symbolic links. To change ownership, use the command :

The above command has a function to change file ownership chownSample. txt. So, output command ls-l will be like this:

-rw-r--r-- 1 whales root 0 Feb 19 22:01 chownSample.txt
lrwxr-xr-x 1 root root 5 Feb 19 7 22:01 symlink -> chownSample.txt

To change the ownership of a symbolic link, use the options -h. The command will be like this:

If using the command ls-l, then the output shown will be like below. It is clear that the ownership of the symbolic link has changed:

-rw-r--r-- 1 whales root 0 Feb 19 22:01 chownSample.txt
lrwxr-xr-x 1 whales root 5 Feb 19 7 22:01 symlink -> chownSample.txt

Recursive Use of Chown

The chown command can be used on directories. But at some point we will get to a recursive directory structure and want to change the ownership of all files and directories.

Using the chown command recursively ensures that the ownership or group of all directories and sub-directories can be changed.

To perform recursive functions, use options -R. An example of the command is as below:

chown -R [USER][:GROUP] Directory

If the directory is something like TestUnix with several subdirectories, then using the command below will change the ownership of all directories and sub-directories to that of user Whales.

chown -R whales /TestUnix

The difference between Chown and Chmod

Now that we understand what chown is, we’ll discuss the difference between chown and chmod next. Following are the differences between chown and chmod based on their functions.

Chown

The chown command, on the other hand, is used to change the ownership of a file or directory. This ownership consists of two parts, namely the owner (owner) and the user group (group).

With the chown command, users can change the owner and user group of a file or directory to another user with appropriate access rights.

Chmod

The chmod command is used to change the access permissions (permissions) of a file or directory. This access permission can be divided into three, namely access rights for the owner (owner), user group (group), and other users (others).

Each of these sections has three types of access rights, namely read, write, and execute. The chmod command allows the user to change these permissions by assigning a combination of three types of permissions to each section.

Broadly speaking, the difference between the two commands is that the chmod command is used to set access rights, while the chown command is used to set ownership.

Be the first to rate it

Avatar of Iwan N
I'm A Web Developer