Chown operation not permitted for root

117,531

Solution 1

The immutable attribute might be set on the file. Remove it with

chattr -i <file>

Solution 2

Several solution exists, some among them:

  • you have a filesystem does not lets you eg. uid:gid, eg: FAT
  • the drive has been mounted read-only
  • SELinux or other security enforcers apply
  • filesystem is set to read-only mode (xfs_freeze, for example)
  • file has the immutable flag set (man chattr)

Solution 3

I had same problem.

$ chattr -V -i dir
chattr 1.41.12 (17-May-2010)
Flags of dir set as s----a---------

Which was not enough. So i added the 'sa'

$ chattr -V -ais dir
chattr 1.41.12 (17-May-2010)
Flags of dir set as ---------------
$ chown root dir
$

Problem solved :)

Solution 4

Funny. Did you check the system logs (/var/log/messages, /var/log/syslog, output of dmesg) for any clues?

Possible reasons:

  • You are running some security-enhanced Linux, such as SELinux. These place restrictions even on what root can do.
  • The file is on a file system that does not support file ownership, such as (V)FAT. Depending on mount options chmod/chown will give you errors.

Solution 5

Try this:

[root@ root]# chattr -ais /bin/ls

after changing the ownership and group back to root.

Share:
117,531

Related videos on Youtube

Peter Stuifzand
Author by

Peter Stuifzand

Updated on September 17, 2022

Comments

  • Peter Stuifzand
    Peter Stuifzand over 1 year

    I try to chown the owner of a file to root, but I can't. I'm doing this as root. I get the following message:

    chown: changing ownership of `ps': Operation not permitted
    
    • Sandokas
      Sandokas almost 15 years
      An ls -lha and lsattr output would aid the solution :)
  • Peter Stuifzand
    Peter Stuifzand almost 15 years
    The problem is my system was hacked and some files were replaced. Now I want to replace them with the originals but I doesn't work.
  • Peter Stuifzand
    Peter Stuifzand almost 15 years
    Filesystem is ext3, mounted read-write, No SELinux.
  • Cian
    Cian almost 15 years
    It's also possible that the file is on an NFS file system, mounted root_squash, albeit unlikely given the file.
  • Cian
    Cian almost 15 years
    If your system was hacked, then you don't want to put files back. You have no way of telling what's been broken, and nothing on the system is trustworthy. Wipe, and reinstall from backups.
  • Peter Stuifzand
    Peter Stuifzand almost 15 years
    It was -a. But thanks for the nod in the right direction.
  • kargig
    kargig almost 15 years
    As Cian said, if your system was hacked and they got root access, don't replace files. It may still contain a (nearly) invisible rootkit that hijacks system calls. It may still be sniffing passwords, it may still have opened backdoors in your services, and and and (infinite number of possible things a hacked machine may contain). The reasonable thing to do is to turn off the machine and study its contents offline, by putting the disk to another box. Don't trust this machine at all and don't replace any binaries, they may contain valuable information to discover what the rootkit does.
  • Zim3r
    Zim3r over 11 years
    Thank you, How can I set immutable attribute on it again?
  • Cian
    Cian over 11 years
    chattr +i <file>
  • andilabs
    andilabs almost 5 years
    chattr: Inappropriate ioctl for device while reading flags on
  • coditori
    coditori about 3 years
    again not permitted!
  • Admin
    Admin about 2 years
    $ chattr -V -i ./nextcloud/ chattr 1.46.2 (28-Feb-2021) chattr: Operation not supported while reading flags on ./nextcloud/ didn't work :(