Sunday, 29 April 2012

Why cannot I change the ownership of my file ?...

For more info visit
A lot of time it would have come to our mind. Why am I not allowed to change the owner of my file in Unix/Linux? Why do I have to be a ROOT user or sudo as a ROOT user when I want to change the ownership of my file? I mean, it's my file. I should have been given the full right to change the owner of my file. Is it necessary for the ROOT to meddle in between !.... I am not trespassing someone else's property. It's not fair enough and blah blah blah...... The answer to all these questions is very simple. Whenever I am changing the owner of my file, it's not something in which only my account is involved. Infact if I had the permission,  it would be like forcing other user to become the owner of my file. So it's kind of dealing with others account also? Now, you may very well ask that why the other user might have problem with this? At the first place, most of the people don't allow anyone to even read their files and look at me, I am giving the ownership of my file to other user. Isn't it fair amount of GENEROSITY. Well, the answer to this question depends on your intentions. Now I will explain it with the help of a simple example that what catastrophe it would have been if you had the permissions to change the owner of your file. Basically everyone knows that they are not allowed to see the contents of /etc/shadow file, which contains password in encrypted format. Though the password for every user is stored in encrypted format, even then you are not allowed to see it. I mean, the ROOT is just taking caution, supposing that some of you could be good hackers. Now I will write a very simple script.   cat>myfile cat /etc/shadow Give all the permissions to everyone for this file.   chmod a+rwx myfile Now we can see, all the users have all the permissions on the file. If you change the ownership of the file from here, supposing that your intentions are to read the contents of shadow file, then let me remind you it would not be very helpful. Even though you can run the file after changing ownership, you will not be allowed to cat /etc/shadow because the script is running with effective UID as your id, who doesn't have the permission to read/write/execute shadow file.  Now you can be smart here, before transferring the ownership to ROOT set SUID for your file.   chmod u+s myfile Then transfer the ownership of your file to ROOT   chown root myfile   Now when the ownership has been transferred and you try to run the file, it would be run with ROOT id as effective UID. So, you would very well be able to see the contents of /etc/shadow file. And then depending on how much you understand encryption/decryption, you could have played a havoc with the system. This is one of the example which justifies that no user should be able to transfer the ownership of their file without ROOT's permission, supposing, in most of the cases ROOT users are trustworthy.

No comments:

Post a Comment