Why chown linux




















Changing File Ownership This section describes how to change the ownership and group ownership of a file. How to Change the Owner of a File Use the following procedure to change the ownership of a file.

Change the owner of a file by using the chown command. A script is a kind of program file. A document file, like a web page, has to be displayed executed by a program file, such as the browser e.

The user in this case has the read permission for the document file which is at the server computer. He also has the execute permission of the browser which is at the client computer. The browser executes the presentation of the web page. The execute permission for a directory allows a user to enter into the directory with the cd command.

The user still needs the read directory permission in order to list the content of the directory. The first column with 10 characters, indicate the permissions for the file or directory on that line. For the second column, if the line is for a file, the value is 1. If it is for a directory, the value can be more than 1. In that case, it would be the number of files and sub-directories in the directory.

The next column indicates the owner principal owner of the file or directory. The column after indicates the group that can use the file or directory. The very first character in the first column can be a dash - , meaning it is for a regular file. After that, there are nine characters in three parts each of three characters.

The first part of three characters shows the permissions for the owner principal owner. This owner is also called the user. The second part of three characters is for the group that can access the file or directory.

The name for this group is given in the fourth field column on the line. The third and last part of three characters, for the first column, shows the permissions for others which can be considered as a large group, which is a very unreliable third owner of the file or directory.

Others does not have a real name and so its name is not indicated in the line; but its permissions are indicated, as the third part of the first column. With the chown command, there is no real exchange of owners. It just replaces the old user with a new user, or replaces the old group with a new group. There are two syntaxes for chown. The one most commonly used is:. FILE should include the path if you are not in the directory of the file.

There can be more than one file for FILE. Remember that the write permission does not include the authority to rename the file, or to delete the file or to move the file. The default group can be changed as explained below. Only the username or group-name is used below. Remember, that ownership is in three sets three levels : the user, the group, and others. The idea for the group is that, instead of giving the same combination of read, write, execute privileges to different users repeatedly, you give it once with a single command to a group of users.

The user executing this command is not the superuser. And so, the new user, john becomes owner of the file, report. The person user executing the command has entered is in the directory that has the file, report.

When using sudo, you may be asked for your password. Here, john might have replaced the old user, peter; and grpA might have replaced the old group, grp1. The user can change his ownership. With the above command lines, ownership can be removed from the wrong person or wrong people.

To change the ownership of a directory and all the files and sub-directories of the sub-tree, use the -R option. And so, the simple syntax becomes:. Here are some examples:. This show some info about user, groups ,permissions , Linux uses groups as a way to organize users. Groups organize collections of accounts, primarily as a security measure. Every user has a default or primary group.

When a user logs in, the group membership is set for their primary group. A user may access other files in other groups, as long as they are also a member of that group and the access permissions are set. To run programs or create a file in a different group, the user must run the newgrp command to switch their current group. A file is owned by a user and a group. By default it is owned by the user who created the file and his default group, unless it is changed.

Outputs like root root from namei -l command mean that the owner and group of that file are both set to root. That's not owner defined or listed twice. Owner and group are two related but different concepts. And a file always has a owner and a group. As to use chown command, great chances are superuser privilege is required, since one is likely to transfer the ownship of a file when using chown command. However, that is not always the truth.

Say, we have a user named 'test', who belongs to several groups. Ubuntu Community Ask! Sign up to join this community. The best answers are voted up and rise to the top. A group can have zero or more users. It can also be a member of other groups on the system as well. Ownership and Permissions: To protect and secure files and directory in Linux we use permissions to control what a user can do with a file or directory. Linux uses three types of permissions: Read: This permission allows the user to read files and in directories, it lets the user read directories and subdirectories stores in it.

Write: This permission allows a user to modify and delete a file. Also it allows a user to modify its contents create, delete and rename files in it for the directories. Unless the execute permission is not given to directories changes does do affect them. Execute: The write permission on a file allows it to get executed.

For example, if we have a file named php.



0コメント

  • 1000 / 1000