My os is Fedora 24 and I tried to test the suid bit functionality.
I wrote below bash as Setuid.bash:
#!/bin/bash
if [ $USER = 'root' ]
then
echo "Like Root Run"
echo "Root User Add in " $(date) >> /etc/SetUid
else
echo "Other User Run"
echo $USER "User Add in " $(date) >> /etc/SetUid
fi
with -rwsrw-r-x. 1 root root 249 May 21 14:45 /bin/Setuid.bash
permission and -rwx------. 1 root root 432 May 21 14:45 /etc/SetUid
Now, when I tried /bin/Setuid.bash
as root I got:
Like Root Run
but when run that with Test user I encountered:
Other User Run
bin/Setuid.bash: line 8: /etc/SetUid: Permission denied
I'll appreciate if any one let me know, where is my way wrong?