Skip to content

Instantly share code, notes, and snippets.

@dpacmittal
Last active October 25, 2017 08:19
Show Gist options
  • Save dpacmittal/8f5bf10c8c6ccfafb9b1acfda53a19d6 to your computer and use it in GitHub Desktop.
Save dpacmittal/8f5bf10c8c6ccfafb9b1acfda53a19d6 to your computer and use it in GitHub Desktop.
Fix web root dir permissions
#!/bin/bash
#Print before executing (so we can know which commands take how long)
set -x
if [ $# -ne 3 ]; then
echo Usage: fix-web-permissions.sh webserver-group username /root/web/dir
echo Eg: fix-web-permissions.sh www-data deepak /var/www
exit 1
fi
WEBSERVER=$1
U=$2
DIR=$3
setfacl --remove-all --remove-default --recursive $DIR
#add user to www-data group
usermod -a -G $WEBSERVER $U
#chown all files to www-data group
chown -R "$WEBSERVER":"$WEBSERVER" $DIR
chmod -R g+rwx $DIR
#set default ACL. For explanation of default acl see - https://www-uxsup.csx.cam.ac.uk/pub/doc/suse/suse9.0/adminguide-9.0/node27.html#SECTION06234000000000000000
#set default mask
setfacl -Rdm "m::rwx" $DIR
setfacl -Rdm "u:$U:rwx,g:$U:rwx" $DIR
setfacl -Rdm "u:$WEBSERVER:rwx,g:$WEBSERVER:rwx" $DIR
setfacl -Rdm "o::r" $DIR
#use setfacl to set mask, permissions, default permissions
setfacl -Rm "m::rwx" $DIR
setfacl -Rm "u:$U:rwx,g:$U:rwx" $DIR
setfacl -Rm "u:$WEBSERVER:rwx,g:$WEBSERVER:rwx" $DIR
setfacl -Rm "o::r" $DIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment