Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A PHP script accidentially changed the right flags (chmod) of a directory to 0. (No access to anybody, including owner). If I have no root access to this server, is it possible to delete the file again with FTP or PHP?

share|improve this question
up vote 6 down vote accepted

Barring some use of ACLs outside the basic permission system, a chmod 000 can be undone without extra authority. The permission bits control access to the contents of the file, but they do not control write access to the permission bits themselves. Typically, root and the file's owner always have write access to the permission bits. So, you should be able to ‘recover’ the file, as long as you can take actions as the file's owner.

$ id -u                                       
$ echo foo > foo                              
$ stat -f '%u %p' foo; cat foo                
501 100644
$ chmod 000 foo
$ stat -f '%u %p' foo; cat foo
501 100000
cat: foo: Permission denied
$ chmod 644 foo
$ stat -f '%u %p' foo; cat foo
501 100644

If you have shell access and your shell user owns the file (or your user can change to the file's owner (su/sudo/…)), then just chmod it back by hand. Otherwise, if you can edit the PHP script (and the PHP runs as the file's owner), just edit it to chmod the file to the desired permissions.

share|improve this answer

If you can amend the PHP that created the file in the first place, perhaps you could make the PHP reset the permissions to what you want...

share|improve this answer

Basically, no. You lost all access to the file. Only root can change the permissions on that file. Contact your system administrator, or the admins of the hosting company or ISP hosting the site.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.