0

Suppose I have a directory with default permission

drwxr-xr-x  4 root  root  4096 Dec 11 23:47 webtorrent-desktop/

I will Change only the owner

$ sudo chown -R sandy webtorrent-desktop 
drwxr-xr-x  4 sandy root  4096 Dec 11 23:47 webtorrent-desktop/

Now I will change the group as well

$ sudo chown -R sandy: webtorrent-desktop <br>
drwxr-xr-x  4 sandy sandy 4096 Dec 11 23:47 webtorrent-desktop/

So, my question is what is the difference between these two
1) I am owner of the file or directory but it's group is root
2) I am owner of the file or directory and group is also mine.

And will I need root permission for some operation in 1st case

1

The difference is who has access to the file.

As you're aware, there are three unique permission bits: the user (u), the group (g), and others (o). Each one of these can be treated differently depending on the set bits.

For example, if a file is set to permissions 770 (rwxrwx---), it means both the owning user and owning group can read, write, and execute the file. If we disable the write bit for the group (resulting in rwxr-x---), it means the owning group can read and execute the file, but not edit it.

So, why is this important? Say you're on a server with a bunch of other people making a website. All of these users are in a group we're going to call developers. We need all of the developers to be able to write to the file, so we give the group read and write permissions. This way, every developer can access the files they need.

Now, let's say there's a folder in our fictional work environment that developers should be able to see, but not change. In that folder, we remove the write permission from the group. This allows devs to see it (and optionally run it), but not change it.

However, as the root user, things are different. Root can already do whatever they want, so it doesn't really matter. It's important to note, though, that when root:root owns a file and write permissions are off for other users, nobody else can edit that file. This is very often used for system configurations that only admin users can touch.

Now, what this means for your two questions:

  1. When you're the owning user and root is the owning group - you control the file entirely, and can set (useless) permissions for root. Similarly, members of the group root (normally just root) can use the file according to the set permissions.
  2. When you're both the owning user and group - you control the file even more entirely. Only your user and your personal group are "owners" and everyone else goes through the "others" permission set.

Functionally on most modern systems, though, there is no difference between modes 1 and 2.

  • Thank you very much for taking your time to write really detailed answer. – Kashyap Kansara Feb 25 '18 at 14:28

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.