如何获取如果程序是使用sudo运行用户的实际UID? [英] How do I get the users real uid if the program is run with sudo?
本文介绍了如何获取如果程序是使用sudo运行用户的实际UID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我运行需要root privledges,因此该计划与须藤
运行,但它也需要知道用户正在运行它。 的getuid
和 geteuid
都返回根
。我如何获得的实际用户的用户名(或UID)?
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)?
谢谢!
推荐答案
须藤
提供了一些环境变量,以帮助您准确这种情况下:
sudo
provides some environment variables to help you with exactly this case:
SUDO_UID Set to the user ID of the user who invoked
sudo
SUDO_USER Set to the login of the user who invoked sudo
这篇关于如何获取如果程序是使用sudo运行用户的实际UID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文