views:

359

answers:

5

On my web server, my file permissions are all over the place and I want to 'reset' everything back to how it originally was. I don't want any users to be able to come in and delete things off my web server! I just want them to be able to look at php pages etc.

What CHMod should I use?

+1  A: 

They should be as restrictive as possible, but no more.

Usually 0644 is a good choice, which gives the owner read and write rights, but everybody else only read. 0755 for directories. But, it can depend on your specific system settings.

carl
Id 644 going to work for the PHP pages mentioned in the question, or will they need the executable bit set too? Might it depend on the web server and how it's configured?
Steve Jessop
No, unless you're doing something really crazy, you don't need the executable bit set for PHP pages. The executable bit allows binary files to be executed and PHP source code is not executable binary.
carl
A: 

I think 644 is standard for files and 755 for directories.

Eric
A: 

If your webserver serves only webpages, without allowing access through (e.g.) anonymous FTP, then incorrect file permissions do not allow users to remove files.

If other people have access to your server through other means (e.g. SSH), then make sure that the write-bit is not set for users other than yourself. Execute:

find . -exec chmod go-w {} \;

This command will restrict the permissions of all files and directories in which it is executed.

Stephan202
Thankyou for your answer, anonymous FTP is not allowed, but I was unsure if people could just go in and delete pages without it.
+2  A: 

If you want to reset everything, do this command and sort out the consequences. Usually 644 is a good permission for files and 711 is for directories. If you allow directory listings, then use 755.

$ find /var/www/html \( -type f -execdir chmod 644 {} \; \) \
                  -o \( -type d -execdir chmod 711 {} \; \)

If you want something less invasive, then just remove the write bits for group and "other".

$ chmod -R go-w /var/www/html
ashawley
A: 

Whichever approach you use, be sure to do some thorough testing if there is any chance that your web application relies files or dirs having certain permissions. While allowing too permissive permissions is probably bad design, this does happen sometimes, so you might break the application.

Dana the Sane

related questions