Since gksu
has been deprecated, I'm using the following script which emulates it using pkexec
:
#!/bin/bash
PKEXEC_USER="root"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-u)
PKEXEC_USER="$2"
shift
;;
-D|-description|-m|--message)
shift # ignore unsupported options with params
;;
-*)
;; # ignore unsupported options with no params
*)
break # no more options
;;
esac
shift
done
pkexec --user "$PKEXEC_USER" env DISPLAY="$DISPLAY" $@
This works great locally, and I was expecting it to work in the ssh -Y
session as well (given that DISPLAY
variable is set), but it doesn't:
pi@raspberrypi:~ $ gksu bash
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/bin/env' as the super user
Multiple identities can be used for authentication:
1. ,,, (pi)
2. root
Choose identity to authenticate as (1-2): 1
Password:
polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized
This incident has been reported.
Why does pkexec
fail, and (less importantly) why isn't it opening a GUI password prompt? Is there any other option I could use, aside from lxqt-sudo
, which would install 150 MB worth of Qt libraries that I don't use otherwise, and is supposedly just as insecure as the original gksudo
.