pkexec visudo (no session for cookie)
Summary
Ran into a situation recently where my /etc/sudoers.d/somefile got corrupted. I also could not use "pkexec" to fix the problem. This is how it was solved thanks to Joshua Estalilla post on this thread
Example
Cannot fix via pkexec due to "No session for cookie".
amide@UL-1710-S:~/Downloads/orabuntu-lxc-master$ pkexec vi /etc/sudoers.d/orabuntu-lxc
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/bin/vi' as the super user
Authenticating as: amide,,, (amide)
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.
amide@UL-1710-S:~/Downloads/orabuntu-lxc-master/anylinux$
Solution
Open Session #1
Open a session as shown below and run the command "echo $$" to get PID.
amide@UL-1710-S:~/Downloads/orabuntu-lxc-master/anylinux$ echo $$
21112
Open Session #2
Open a session and run the following command as shown below. Everytime you run a pkexec command in Session #1 , Session #2 will prompt for a password to allow the Session #1 activity.
amide@UL-1710-S:~/Downloads/orabuntu-lxc-master/installs/logs$ pkttyagent --process 21112
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: amide,,, (amide)
Password:
==== AUTHENTICATION COMPLETE ===
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: amide,,, (amide)
Password:
==== AUTHENTICATION COMPLETE ===
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run `/usr/sbin/visudo' as the super user
Authenticating as: amide,,, (amide)
Password:
==== AUTHENTICATION COMPLETE ===