My aim is to edit the file (whose owner is user1) using a script where user2 doesn't have permission to directly edit the file but it should be edited when executed through script by user2. So I set SUID on the script My script has the following content
#!/bin/sh
echo "Enter variable a"
read a
echo "Enter path"
read Path
echo "Enter variable b"
read b
sed -i -c "/#Hello variable \<$a\>/{h;n;s/\$Initial_Value=.*/\$Initial_Value=$b/}" "$Path"
The script replaces some matching pattern in the file provided as input Permissions of the script are as follows
-rwsr-xr-x 1 user1 user1 648 Jul 21 08:03 Script.ksh
Permissions of the file which script modifies are as follows
-rwxrwxr-x 1 user1 user1 224 Jul 21 10:46 file
Permissions of the directory under which the file is present are as follows
drwxrwxr-x 6 user1 group1 122880 Jul 22 11:17 directory
The script is executed by user2 who is part of group1 where the file exists, and executing user2 will not have permissions to directly edit the file.
To edit the file indirectly using script I have set SUID bit on the script. I thought that when executed by user2 it will get executed with the permissions of user1 But when I am executing the script, SED is giving below error.
sed: cannot copy Path/sedFKvRSo to Path/file: Permission denied