chown: changing ownership of ` ': Operation not permitted

24,246

You need to be root to change the ownership of a file. Ordinary users can't do that.

Otherwise it would be easy to get a root access by just using chmod to set the SETUID bit and then changing the ownership to root.

Share:
24,246

Related videos on Youtube

JohnMerlino
Author by

JohnMerlino

Looking to master Trigonometry and Calculus and an interest in Ruby and JavaScript programming languages. I only use Linux (in particular Ubuntu Desktop) and Android. I like to write as well.

Updated on September 18, 2022

Comments

  • JohnMerlino
    JohnMerlino almost 2 years

    I know this is possible duplicate but I looked at other answers and wasn't satisfied with the responses. You should be able to use the chown command if you are the super user OR the owner of the file. Well, in my case I am the owner of the file, and I want to use chown. But I want to change ownership of file to super user, so I type following:

    $ chown root testfile
    

    But it gives me error:

     chown: changing ownership of `testfile': Operation not permitted
    

    However, I am the owner of the file, and granted myself read, write, and execute permission on the file:

    -rwx------  1 viggy viggy      10 Nov 14 13:01 testfile
    

    So as the owner of the file, why can I not change ownership of the file?

  • JohnMerlino
    JohnMerlino over 11 years
    So the Ubuntu documentation is wrong when it says you can use chown if you are the super user OR the owner of the file. Apparently, being the owner doesn't suffice.