我喜欢通过cron修复我们的文件服务器的权限。 一般来说,我喜欢将所有内容都设置为umask 027,忽略用户所做的任何更改。 对于某些子文件夹,我喜欢应用umask 077。
问题不在于如何设置和使用umask,而是通过cronjob重复修改权限,以防用户更改了某些内容。
例如最后应该看起来像
drwx —— /home/user/.ssh
drwxr-x — / hom / user / foobar
drwx —— / hom / user / Mail
困难的方式(我想要的)看起来像这样:
chmod -R o-rwx /home/user chmod -R g+r /home/user find /home/user -typer d -exec chmod g+x '{}' \; chmod go-rwx /home/user/{Mail,.ssh}
以下是我们用于类似的东西(对于不是由root拥有的所有文件夹)。 看似不必要的find命令是为了确保我们不设置正确设置的任何文件夹的权限。 以前的脚本盲目地修改所有文件夹会导致我的一些备份认为文件已经改变了中间备份,而且我每天都浪费了大量的备份相同文件的介质。
由此产生的权限集:
#!/bin/sh cd /home/CAE # For all directories except those owned by root for user in `ls -l | grep -v ' root ' | egrep '^d' | awk '{print $NF}'`; do cd /home/CAE # Fix top-level permissions to avoid people browsing accounts, but # to allow normal Web access to public_html find . -mindepth 1 -maxdepth 1 -name ${user} -type d ! -perm 0711 -print0 | xargs -r -0 chmod 711 # Make sure user has a Web directory (and a private one, also) if [ ! -d ${user}/public_html/private ]; then mkdir -p ${user}/public_html/private chown -R ${user}:users ${user}/public_html fi cd ${user}/public_html # Set top-level private folder to mode 711 if it isn't already find . -mindepth 1 -maxdepth 1 -name private -type d ! -perm 0711 -print0 | xargs -r -0 chmod 711 # Set all directories except top-level private to mode 755 that aren't already find . -maxdepth 1 -type d ! -name private ! -perm 0755 -print0 | xargs -r -0 chmod 755 find . -mindepth 2 -type d ! -perm 0755 -print0 | xargs -r -0 chmod 755 # Set all files mode 644 that aren't already find . -type f ! -perm 0644 -print0 | xargs -r -0 chmod 644 done
请原谅我,如果我错过了这一点,但它看起来像你想要一个crontab条目相当频繁地运行以下命令:
chmod -R go-rwx /home/user/.ssh chmod -R gw /home/user/foobar chmod -R o-rwx /home/user/foobar chmod -R go-rwx /home/user/Mail
或者那不是你要求怎么做?
您可以使用acl支持安装分区,并使用getfacl&setfacl命令进行恢复备份。