下面显示了tomcat在删除owner是自己的文档时出错了,提示permission denied.
这是因为用户tomcat在该文档的父目录权限里并没有w的权限.虽然tomcat是该文档的owner,但是删除该文档也是对父目录的修改,因此在用户没有父目录的w权限里,提示权限不足
drwxr-xr-x 2 root root 4096 nov 21 21:02 tomcat
drwxr-xr-x. 13 root root 4096 may 30 21:42 usr
drwxr-xr-x. 19 root root 4096 jul 15 02:29 var
[root@wang ~]# touch /tomcat/xxx
[root@wang ~]# chown tomcat:tomcat /tomcat/xxx
[root@wang ~]# ll /tomcat/xxx
-rw-r--r-- 1 tomcat tomcat 0 nov 21 21:03 /tomcat/xxx
[root@wang ~]# su - tomcat
[tomcat@wang ~]$ rm -rf /tomcat/xxx
rm: cannot remove `/tomcat/xxx': permission denied
[tomcat@wang ~]$
修改父目录的权限,将w的权限给予用户tomcat
[root@wang tomcat]# chmod 757 /tomcat
从下图中可见,用户tomcat对于xxx文档的父目录/tomcat有w的权限,所以删除成功了
drwxr-xrwx 2 root root 4096 nov 21 21:03 tomcat
drwxr-xr-x. 13 root root 4096 may 30 21:42 usr
drwxr-xr-x. 19 root root 4096 jul 15 02:29 var
[root@wang tomcat]# su - tomcat
[tomcat@wang ~]$ rm /tomcat/xxx
[tomcat@wang ~]$ ll /tomcat/
total 0
[tomcat@wang ~]$
也可以直接把父目录的owner转给tomcat,最快的方法,这里还用了递归,其实不用也可以
[root@wang tomcat]# chown -r tomcat:tomcat /tomcat