Skip to content

Instantly share code, notes, and snippets.

@ViktorStiskala
Created May 12, 2011 19:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ViktorStiskala/969269 to your computer and use it in GitHub Desktop.
Save ViktorStiskala/969269 to your computer and use it in GitHub Desktop.
Allow users from www-data group to change owner of files under /var/www
#!/bin/bash
# Resursively change owner to www-data
#
# Created: 2011-05-12
# Author: Viktor Stiskala <viktor@stiskala.cz>
LOGFILE=/var/log/wwwdata
## Add following line tu sudoers file (using visudo command) in order to allow
## users from www-data group to change owners under /var/www/
## Don't forget to check that this file is owned by root and has the 700 perms
##
## %www-data ALL=(root) /usr/local/bin/wwwdata
##
## (assuming that you have this file installed in /usr/local/bin/wwwdata)
for i in "$@";
do
if [[ `realpath "$i" 2>/dev/null` != "/var/www/"* ]]
then
echo "Running this command on path in other location than /var/www/ is not permitted" 1>&2
exit 1
fi
done
# new loop to avoid changing permissions of only some of the paths entered because of the permission error
for i in "$@";
do
chown -R www-data:www-data "$i"
if [[ ! -z "$LOGFILE" ]]
then
echo `realpath "$i" 2>/dev/null` >> "$LOGFILE"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment