# Why my SETUID does not work as expected?

**URL:** <https://community.unix.com/t/why-my-setuid-does-not-work-as-expected/356778>\
**Category:** Shell Programming and Scripting\
**Created:** [November 16, 2015, 3:31am UTC](https://community.unix.com/t/why-my-setuid-does-not-work-as-expected/356778 "2015-11-16T03:31:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![summer\_cherry](https://community.unix.com/letter_avatar/summer_cherry/32/5_5575768a8748004e209b776fc1b2916d.png) [@summer\_cherry](https://community.unix.com/u/summer_cherry)\
**Post date:** [November 16, 2015, 3:31am UTC](https://community.unix.com/t/why-my-setuid-does-not-work-as-expected/356778/1 "2015-11-16T03:31:06Z")

</div>

Hi All,

Thanks for your help in advanced.

Could you please kindly help on why my SETUID does not work?

create a file, only root can read write it

```nohighlight
/tmp>ls -l a.log
-rw------- 1 root root 3 Nov 12 18:57 a.log

```

create a script under root with SETUID

```nohighlight
/tmp>ls -l a.sh
-rwsr-sr-x 1 root root 23 Nov 16 00:18 a.sh

```

the script will read above created file

```nohighlight
/tmp>cat a.sh
#! /bin/bash
cat a.log

```

run under non-root account, but still failed? why?

```nohighlight
/tmp>a.sh
cat: a.log: Permission denied

```

Is it due to 'cat' is not setuid? If so, how can I modify my script to let SETUID take effect?

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 16, 2015, 4:02am UTC](https://community.unix.com/t/why-my-setuid-does-not-work-as-expected/356778/2 "2015-11-16T04:02:15Z")

</div>

I vaguely remember having read that certain systems' shells can't be run setuid. Try printing the effective UID from within the script.

---

<div class="post-metadata">

**Author:** ![rbatte1](https://community.unix.com/letter_avatar/rbatte1/32/5_5575768a8748004e209b776fc1b2916d.png) [@rbatte1](https://community.unix.com/u/rbatte1)\
**Post date:** [November 16, 2015, 9:07am UTC](https://community.unix.com/t/why-my-setuid-does-not-work-as-expected/356778/3 "2015-11-16T09:07:42Z")

</div>

Is this script in a non-SUID filesystem perhaps? Have a look at the mount options for the filesystem that the script is in. You can probably get it by:-

```nohighlight
df /path/to/your/script

```

You can then review /etc/fstab, /etc/vfstab or /etc/filesystems as applicable to your operating system (you don't say which, so these are the most common)

You might also get the same information from the mount command by itself, but this may be OS specific, so I'd be less sure about that.

Does that help?  
Robin

---

<div class="post-metadata">

**Author:** ![fpmurphy](https://community.unix.com/user_avatar/community.unix.com/fpmurphy/32/110_2.png) [@fpmurphy](https://community.unix.com/u/fpmurphy)\
**Post date:** [November 17, 2015, 9:33pm UTC](https://community.unix.com/t/why-my-setuid-does-not-work-as-expected/356778/4 "2015-11-17T21:33:10Z")

</div>

Linux and most other Unix-like OSes by design ignore the setuid bit on an executable script.
