Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

3 Answers

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                                       
501
$ echo foo > foo                              
$ stat -f '%u %p' foo; cat foo                
501 100644
foo
$ 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
foo

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
add comment

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
add comment

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
add comment

Your Answer

 
discard

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.