I have small script which creates a tmp files using mkstemp. My script was created using root user , but if I logged in as someother user other than root then my scripts runs but msktemp fails and says permission denied

sh: /tmp/tmpFile-khB5hH: Permission denied

Same thing while doing in RHEL 7 works and no Permission denied error, what is changed in RHEL 8. looks like RHEL 8 is checking logged on user vs effective user.

I tested this up in RHEL 7.5 and RHEL 8.4.

If someone know change in RHEL 8 which leads to permission problems please suggest. Thanks

  • 2
    What does ls -ld /tmp output? See also unix.stackexchange.com/questions/71622/…
    – Kusalananda
    Aug 13 at 17:12
  • + what does touch /tmp/foo output ?
    – steve
    Aug 13 at 17:17
  • @Kusalananda drwxrwxrwt. 9 root root 195 Aug 15 06:48 /tmp
    – cjoshi
    Aug 15 at 11:49
  • @steve nothing as such.
    – cjoshi
    Aug 15 at 11:50
  • @steve well problem is happening because my logged on user is different from the effective use ..hence it says permission denied which it should not do. mkstemp is able to create the temp file in /tmp when logged on user and my script user is same.....thought in RHEL7 it works fine
    – cjoshi
    Aug 15 at 11:53

I have set the logged on user in my script by seteguid(getuid()) this work though it is dangerous. this make logged on user as always effective user and it doesnt fail on RHEL8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.