Permissions on dreamhost are a pain:
- too restrictive, and apache doesn’t have access
- not restrictive enough, and apache will refuse to run them in cgi
- not restrictive enough, and other people can read one’s passwords and so on
I did some house-keeping this morning, and decided to write some scripts to make my life simpler:
- setwebperms.sh Applies restrictive permissions on a web directory
- setprivateperms.sh Applies permissions on a directory so only your own account has read or write access
- setgroupreadperms.sh Anyone in the file’s linux group can read the files, but not write, and other people can’t even read them
- setotherreadperms.sh As setgroupreadperms.sh, but for everyone. As setwebperms.sh, but allows directory listings
These scripts can be found at http://hughperkins.com/download/dreamhostperms.tar.bz2.
Use them at your own risk, your mileage may vary. The tricky thing with perms scripts is, well there are several:
- we don’t want to change the permissions on files that are already correct, otherwise we affect other scripts that detect changes to our web directory by looking at ctime.
- perms on scripts should be something like 700, but on static content, like html and gifs, should be something like 644
- perms on directories should be either 700 (user only), 711 (traversal but no listing), or 755 (read only, full listing and travers
Solutions used:
- To avoid modifying files that are already correct, we use ‘find ! -perm’.
- We run the find command separately for each file suffix, and filetype, so we can specify precisely the appropraite permissions
You can check inside each script to see how files are classified as dynamic or static, or simply left alone (if not classified).
Config files such as LocalSettings.php or wp-config.php are both counted as dynamic scirpt files, so get 700 permissions when using setwebperms.sh, which keeps them secure from other linux users on the shared hosting.
I ran setwebperms.sh on my entire website this morning, and everything seems to work ok still, so that is cool!
One last point, setwebperms.sh prevents directory listings, which means that directory listings by apache when it doesnt find an apropriate index file will be forbidden. You can get round that by downloading:
http://hughperkins.com/download/directoryindexer.tar.bz2 and adding the index.cgi file inside into any directory you want to be indexed by apache. It is simply a python script that prints an ‘a’ link for each file in the directory which doesnt start with ‘.’ and isn’t index.cgi itself.
Edit: looks like if you go to the dreamhost panel, select ‘users’ and click on a user, then you can select ‘increased security’, which will prevent anyone, even another of your accounts, from being able to read anything from that account, even if they know the exact path, and independent of the permissions on that file. It changes the group and permissions on the home directory itself, right at the top, and that prevents traversal to any other files and directories. Apache is not affected and runs fine.