The following shows that tomcat made an error when deleting the document whose owner is itself, prompting Permission denied.
This is because the user tomcat does not have w permissions in the parent directory permissions of the document. Although tomcat is the owner of the document, Deleting the document is also a modification to the parent directory, so if the user does not have the w permission of the parent directory, it will prompt that the permission is insufficient
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 ~]$
Modify the permissions of the parent directory and give the w permission to the user tomcat
[root@wang tomcat]# chmod 757 /tomcat
As can be seen from the picture below, the user tomcat has w permissions on the parent directory/tomcat of the xxx document, so the deletion was successful
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 ~]$
You can also directly transfer the owner of the parent directory to tomcat. The fastest way is here. I used recursion, but I can actually do it without it
[root@wang tomcat]# chown -R tomcat:tomcat /tomcat