A and B are both non-root users in a same group. Suppose there will be some B owned garbage files generated inside a directory(also generated and owned by B) after a regression run by B, but I need A to do the clean up job in case B's regression is terminated and can not do the clean up properly.I know the easiest way is to let B set umask 0002 before the regression, but unfortunately, somehow the regression tool will override this setting, and generate garbage files writable only by B.So I try to use suid feature to do the trick.the demo directory is as bellow/proj/ttt> lltotal 0-rw-r--r-- 1 B users  0 Mar 16 00:50 garbage.fileI try to create a script(cleanup) owned by B to clean up garbage files.#!/bin/bash# cleanupecho EUID=$EUID UID=$UIDrm -f garbage.filethen I add suid to this script with chmod ug+s cleanup. The directories becomes/proj/ttt> lltotal 0-rwsr-sr-x 1 B users 57 Mar 16 00:50 cleanup-rw-r--r-- 1 B users  0 Mar 16 00:50 garbage.fileI also add the s bit for the parent directoriesdrwsr-sr-x 2 B users 4096 Mar 16 00:57 tttBut when I execute this script as A, It seems the 's' bit not work and A can not delete the garbage file./proj/ttt> ./cleanup   # executed by AEUID=25264 UID=25264   # user B's uid is 25220, user A's uid is 25264rm: cannot remove `garbage.file': Permission deniedI don't know what's wrong with my try, or if this approach is feasible in the end?Or is there any other better way to do the job?
How to let user A delete B's file on behalf of B?
files;rm;setuid