下面显示了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 [[email protected] ~]# touch /tomcat/xxx [[email protected] ~]# chown tomcat:tomcat /tomcat/xxx [[email protected] ~]# ll /tomcat/xxx -rw-r--r-- 1 tomcat tomcat 0 Nov 21 21:03 /tomcat/xxx [[email protected] ~]# su - tomcat [[email protected] ~]$ rm -rf /tomcat/xxx rm: cannot remove `/tomcat/xxx‘: Permission denied [[email protected] ~]$
修改父目录的权限,将w的权限给予用户tomcat
[[email protected] 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 [[email protected] tomcat]# su - tomcat [[email protected] ~]$ rm /tomcat/xxx [[email protected] ~]$ ll /tomcat/ total 0 [[email protected] ~]$
也可以直接把父目录的owner转给tomcat,最快的方法,这里还用了递归,其实不用也可以
[[email protected] tomcat]# chown -R tomcat:tomcat /tomcat
时间: 2024-11-01 11:34:31