How do I get the users real uid if the program is run with sudo?

前端 未结 4 1630
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 20:52

The program I am running needs root privledges and therefore is run with sudo, but it also needs to know what user is running it. getuid and

4条回答
  •  生来不讨喜
    2021-01-07 21:05

    A Linux-specific audit_getloginuid() function provided by the auditing system may be able to help; since pam_loginuid(8) is only going to be installed for the "main" daemons (sshd, login, gdm, etc.) the audit uid will remain unchanged when sudo(8) executes.

    This will require a little configuration; add:

    session    required     pam_loginuid.so
    

    to the /etc/pam.d/sshd file -- and whichever other services you allow your users to use.

    Ensure pam_loginuid.so isn't loaded in the /etc/pam.d/sudo configuration file.

提交回复
热议问题