Secure Drupal Script

Public

secure-drupal.sh

Get raw version
bash
  1. #!/bin/bash
  2.  
  3. path="/var/www"
  4. user="ubuntu"
  5. group="www-data"
  6.  
  7. cd $path;
  8.  
  9. echo -e "Changing ownership of all contents of \"${path}\" :\n user => \"${user}\" \t group => \"${group}\"\n"
  10. chown -R ${user}:${group} .
  11. echo "Changing permissions of all directories inside \"${path}\" to \"750\"..."
  12. find . -type d -exec chmod u=rwx,g=rx,o= {} \;
  13. echo -e "Changing permissions of all files inside \"${path}\" to \"640\"...\n"
  14. find . -type f -exec chmod u=rw,g=r,o= {} \;
  15.  
  16. cd $path/sites;
  17.  
  18. echo "Changing permissions of \"files\" directories in \"${path}/sites\" to \"770\"..."
  19. find . -type d -name files -exec chmod ug=rwx,o= '{}' \;
  20. echo "Changing permissions of all files inside all \"files\" directories in \"${path}/sites\" to \"660\"..."
  21. find . -name files -type d -exec find '{}' -type f \; | while read FILE; do chmod ug=rw,o= "$FILE"; done
  22. echo "Changing permissions of all directories inside all \"files\" directories in \"${path}/sites\" to \"770\"..."
  23. find . -name files -type d -exec find '{}' -type d \; | while read DIR; do chmod ug=rwx,o= "$DIR"; done

Comments

lelizondo's picture

Found this script somewhere. If you use it, don't forget to make it executable and change the first three variables of the script.