27

When I use chmod() to change permissions at run time, it gives me the below message:

Warning: chmod() [function.chmod]: Operation not permitted in /home/loud/public_html/readalbum.php

How can I remove this error and make the chmod function work?

random
  • 9,774
  • 10
  • 66
  • 83
Deepak
  • 1,055
  • 4
  • 13
  • 22
  • 5
    Down-voted for using PHP to solve the problem and then accepting terminal answer when the question *did not involve the use of the terminal in the first place*! – John Mar 17 '19 at 18:46

4 Answers4

30
$ sudo chmod ...

You need to either be the owner of the file or be the superuser, i.e., user root. If you own the directory but not the file, you can copy the file, rm the original, then mv it back, and then you will be able to chown it.

The easy way to temporarily be root is to run the command via sudo. ($ man 8 sudo)

DigitalRoss
  • 143,651
  • 25
  • 248
  • 329
  • 1
    Indeed, the edited answer helped me out a lot, since I completely forgot about copypasta hijacking. – John Dec 08 '09 at 11:16
  • You also need to apply sudo to each command run if you're running them in a one-liner (or sudo su). – timelmer Jun 27 '18 at 04:57
3

In order to perform chmod, you need to be owner of the file you are trying to modify, or the root user.

Martin v. Löwis
  • 124,830
  • 17
  • 198
  • 235
3

This is a tricky question.

There a set of problems about file permissions. If you can do this at the command line

$ sudo chown myaccount /path/to/file

then you have a standard permissions problem. Make sure you own the file and have permission to modify the directory.

If you cannnot get permissions, then you have probably mounted a FAT-32 filesystem. If you ls -l the file, and you find it is owned by root and a member of the "plugdev" group, then you are certain its the issue. FAT-32 permissions are set at the time of mounting, using the line of /etc/fstab file. You can set the uid/gid of all the files like this:

UUID=C14C-CE25  /big            vfat    utf8,umask=007,uid=1000,gid=1000 0       1

Also, note that the FAT-32 won't take symbolic links.

Wrote the whole thing up at http://www.charlesmerriam.com/blog/2009/12/operation-not-permitted-and-the-fat-32-system/

Charles Merriam
  • 19,908
  • 6
  • 73
  • 83
-1

You, or most likely your sysadmin, will need to login as root and run the chown command: http://www.computerhope.com/unix/uchown.htm

Through this command you will become the owner of the file.

Or, you can be a member of a group that owns this file and then you can use chmod.

But, talk with your sysadmin.

James Black
  • 41,583
  • 10
  • 86
  • 166
  • 2
    It seems more likely that the OP doesn't *have* a 'sysadmin'. – pavium Oct 20 '09 at 03:46
  • Then he will need to login as root, but that is why I gave the link for chown, as talking through group membership would be a bit more work. – James Black Oct 20 '09 at 03:47