如果我在没有 pkexec 的情况下执行 print os.environ
,我会得到很多有用的系统环境变量,但是,一旦我执行了,它们中的大部分都消失了。我怎样才能使用 pkexec 找回它们?我知道有一个使用 sudo 的解决方法,但还没有找到 pkexec 的解决方法
最佳答案
简而言之,你不能。来自pkexec
man page :
The environment that PROGRAM will run in will be set to a minimal known and safe environment in order to avoid injecting code through LD_LIBRARY_PATH or similar mechanisms. In addition the PKEXEC_UID environment variable is set to the user id of the process invoking pkexec.
您可以使 pkexec
保留一些环境变量(即通过保留 $DISPLAY
和 $XAUTHORITY
允许 X11 程序工作)使用org.freedesktop.policykit.exec.allow_gui
注释。但是,保留所有环境变量似乎是故意拒绝的决定。
关于python - 通过 pkexec 执行时缺少环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42960140/