I'm executing a python script as root with pkexec and I'm using working_dir = os.getenv('HOME')
to get the username but it always returns root
instead of test1
which is the current user.
How can I get the user that ran pkexec instead?
I already tried print os.environ["SUDO_USER"]
but that fails since it's not being executed directly with sudo. I am on trusty now but behaves the same in 16.04.
PKEXEC_UID
, so you'd need to find a (non evil) way to derive the home directory from that – steeldriver Mar 14 '17 at 2:05print os.environ["PKEXEC_UID"]
I managed to get the normal user's uid. I just need to get the name of the user from the uid and this should solve my problem which is less complicated – answerSeeker Mar 14 '17 at 2:07