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 geteuid both return root. How do I get the actual users username (or uid)?
Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
sudoprovides some environment variables to help you with exactly this case:steveayre has pointed out in the comments that the user can set these environment variables in some cases; the
sudo(8)manpage includes in part:So be sure that you don’t grant
ALLcommands to users when you need to rely upon this feature.