Changing Ownership: "Operation not permitted" - even as root!

395,021

Probably the file has the immutable flag set in its extended attributes:

user@user-X550CL ~/tmp % touch immutable
user@user-X550CL ~/tmp % sudo chown root:root immutable
[sudo] password for user:
user@user-X550CL ~/tmp % sudo chattr +i immutable
user@user-X550CL ~/tmp % lsattr immutable
----i--------e-- immutable
user@user-X550CL ~/tmp % sudo chown user:user immutable
chown: changing ownership of 'immutable': Operation not permitted

To fix this, just run sudo chattr -i file:

user@user-X550CL ~/tmp % sudo chattr -i immutable
user@user-X550CL ~/tmp % lsattr immutable
-------------e-- immutable
user@user-X550CL ~/tmp % sudo chown user:user immutable
user@user-X550CL ~/tmp % 
Share:
395,021

Related videos on Youtube

David
Author by

David

Computer Engineering Tech Major Fluent in .NET, bash, and TypeScript AU User since mid-2015 Using ubuntu since 9.04

Updated on September 18, 2022

Comments

  • David
    David almost 2 years

    I am trying to help a user solve an issue with a bootable USB drive, but there seems to be a file whose ownership cannot be edited. I thought it would have been possible with:

    sudo chown user:user ldlinux.sys
    

    When that is executed, however, terminal gives this error:

    Operation not permitted
    

    The extended chat I had with the user can be found here.

    • Byte Commander
      Byte Commander almost 9 years
      Maybe checking ACLs is an option? I commented on the original question and asked for the output of getfacl ldlinux.sys
    • muru
      muru almost 9 years
      I think the USB is mounted read-only. Ask OP to check mount options via mount.
    • userDepth
      userDepth almost 8 years
      AFAIK it is (users:username) not just the user
    • gaoithe
      gaoithe over 4 years
      users:username ?? it is user:group
  • A.B.
    A.B. almost 9 years
    Thanks for the explanation. I forget it again and again. ;)
  • TenLeftFingers
    TenLeftFingers about 8 years
    I get: chattr: Inappropriate ioctl for device while reading flags on 64GB, while trying this on a usb thumb drive at /media/
  • Jonathan Parent Lévesque
    Jonathan Parent Lévesque almost 8 years
    For me, the "a" (Append only) flag was the problem. sudo chattr -a fileName solved the problem.
  • Brent Faust
    Brent Faust over 6 years
    +1, but fails for some files (not just symlinks), even running as root sudo chattr -i returning chattr: Operation not supported while reading flags.
  • harperville
    harperville over 3 years
    My USB has msdos filesystem. Found this: unix.stackexchange.com/questions/552121/… so I went ahead and reformatted as ext4 per askubuntu.com/questions/149984/…
  • sonrad10
    sonrad10 almost 3 years
    You get the Operation not supported error when trying to mount a Windows filesystem (exFat/NTFS) with incorrect mount options. You can either reformat your drive to ext4, or simply change the mount options with this answer: askubuntu.com/a/956072/612853
  • linstar
    linstar over 2 years
    Thanks kos, this solved it for me just now.. But, man chattr doesn't even list -i as an option! So, thanks again.