Environment variables missing when executing via pkexec

时间:2017-03-22 18:41:13

标签: python linux

If I execute print os.environ without pkexec I get lots of useful system environment variables, however, once I execute with, most of them are gone. How can I get them back with using pkexec? I understand there's a workaround using sudo but haven't found one yet for pkexec

1 个答案:

答案 0 :(得分:3)

总之,你不能。来自pkexec man page

  

将运行PROGRAM的环境设置为最小的已知和安全环境,以避免通过LD_LIBRARY_PATH或类似机制注入代码。此外,PKEXEC_UID环境变量设置为调用pkexec的进程的用户标识。

您可以pkexec使用$DISPLAY注释保留一些环境变量(即允许X11程序通过保留$XAUTHORITYorg.freedesktop.policykit.exec.allow_gui来工作)。但是,保留所有环境变量似乎是故意拒绝的决定。