Sample Header Ad - 728x90

How do I run GUI applications as root by using pkexec?

26 votes
3 answers
37893 views
I am using [Trisquel](https://trisquel.info) GNU/Linux-Libre which comes with [Gnome3 Flashback](https://wiki.gnome.org/Projects/GnomeFlashback) Desktop Environment. I know that I can run GUI application as root by sudo & gksudo but I want to know that How do I run GUI applications as root with the help of **pkexec**? When I tries to run gedit (or any other application like:nautilus) by pkexec gedit then It prompts for password for authentication:- screenshot After entering password it exit with error:- $ pkexec gedit error: XDG_RUNTIME_DIR not set in the environment. (gedit:6135): Gtk-WARNING **: cannot open display: ---------- So, It seems something is going wrong with display environment. I've also tried with DISPLAY=:0 pkexec gedit but doesn't work. ---------- Following information is available from man pkexec:- > The environment that PROGRAM will run it, will be set to a minimal > known and safe environment in order to > avoid injecting code through LD_LIBRARY_PATH or similar mechanisms. In addition the PKEXEC_UID environment > variable is set to the user id of the process invoking pkexec. As a result, pkexec will not allow you to run > X11 applications as another user since the $DISPLAY and $XAUTHORITY environment variables are not set. These > two variables will be retained if the org.freedesktop.policykit.exec.allow_gui annotation on an action is > set > to a nonempty value; this is discouraged, though, and should only be used for legacy programs. Now I don't know What to do in order to accomplish this. Thus, Help me to find out How to run GUI applications as root by means of pkexec. Or **Is this possible or not?** ---------- BTW, Inspired by gparted-pkexeccommand which works fine. How gparted use pkexec?
Asked by Pandya (25613 rep)
May 13, 2015, 09:37 AM
Last activity: Nov 11, 2021, 06:01 PM