Linux
Debian
polkit

Running pkexec on environments without GUI (and with X transfer)

If you try to run pkexec on SSH, you might get the following error even if the host machine has GUI session:

==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/bin/apt-get' as the super user
Authenticating as: root
Password: 
polkit-agent-helper-1: error response to PolicyKit daemon: GDBus.Error:org.freedesktop.PolicyKit1.Error.Failed: No session for cookie
==== AUTHENTICATION FAILED ===

This means host machine GUI session's policykit agent cannot be launched on SSH. So we need to have a standalone agent.

sudo apt-get -y install policykit-1-gnome # only first time
/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1 &