Understanding Unix Owner and chmod 777 Understanding Unix Owner and chmod 777 unix unix

Understanding Unix Owner and chmod 777


  1. The file can only have '1 owner', though if you wish to have mutiple 'owners' this is where groups come in. If alice and john are part of a group called 'hello' and the group 'hello' is assigned as the group owner, then alice and john are owners (as a part of the group) to the file. In the traditional sense however, no, there is only 1 owner. I often keep the root as the designated owner, and then incorporate groups as needed.
  2. chmod is used to change the permissions of the actual file. When you execute chmod 777, you are allowing RWX (read, write, execute) access to owners, groups, and others. It would not achieve the same success as chmod does not actually change the ownership, which chown does. So chmod is in reference to defining who can do what to a file, chown is determining who owns the file.
  3. No, they cannot change as they are not the owner of the file, but are owners as a 'member' of a group. And the command would actually be chmod u-r. '-' (minus) removes access and '+' (plus) adds.


You must not confuse: access rights and ownership.

If someone owns an object it has rights to do whatever he wants with it, including modifying access rights and ownership. Be aware that once someone resign for ownership he cannot get it back on his own. So, if you own a house you can manage it the way you want and let people enter or not.

Access rights define who can do what on a file, independently from ownership. I suppose it is frequent for you to enter a building without asking for ownership, this is the same.

Access rights just define if someone (or a group or a set of users) has the right to read the content, modify the content or execute the content (at least basically). But properties like ownership, access rights are not parts of content of the file, they are meta-data associated to, and modifying theses meta-data is possible in very special ways. Ownership and access rights for instance can only be modified by owner.

Now:

A file can have multiple owners?

Yes it is possible but not with the basic access rights and ownership as describes. In basic Unix, there can be only a single owner.

What is the use of chown if chmod 777 can help achieve the same task?

chown is ownership transfer (you sell your house). chmod is just a way to modify policy for people entering the house.

Can a user in 'chmod 777 group' restrict the access of the actual owner by the command chmod u=r filename?

Don't know what 'chmod 777 group' is. But nobody except owner (and root but root is a very special user) can change any such metadata (ownership, access right).


Imagine you have 3 users on your system: krishnendu, mindy and wodin

krishnendu is in the following groups: krishnendu, staff, guests

mindy is in the following groups: mindy, staff

wodin is in the following groups: wodin, guests

The only member of the krishnendu group is the krishnendu user. The mindy and wodin groups are similar.

If you have a file (file1) owned by krishnendu and group krishnendu with mode 640 then only the krishnendu user has read/write access to the file.

If you chown the file without changing the mode: chown mindy file1 then it will still have group ownership of krishnendu and mode 640. This means that mindy will have read/write access, but the krishnendu user (because krishnendu is a member of the krishnendu group) will also have read-only access.

If you chmod 777 file1 after that, then it will still be owned by mindy with group ownership of krishnendu, but now all three users will have read/write/execute access to the file.

There can be only a single owner of a file. If you want to give a subset of users access while denying the other users on the system access you need to put that subset of users in a group and use chown or chgrp to change the files group owner.

e.g. if you create files file2 and file3, both with mode 640, and then do the following:

# chown root:staff file2# chown root:guests file3

then only krishnendu and mindy will have access to file2, because they are in the staff group, but wodin is not. And only krishnendu and wodin will have access to file3 because they are in the guests group, but mindy is not.

So setting the file mode to 777 is not the same as changing the file owner.

Also, you generally don't want to use mode 777 for anything.

If a file has mode 777 it does not give any users other than root or the owner the ability to change the ownership or the mode.