[HOW TO] Improve Launching Apps as Root (GKSU)

In the old days, we used to use the command "gksu" to launch a graphical application with sudo privileges.
In recent times (Beginning at Zorin 15 for us Zorin users), gksu was deprecated.
This left some scrambling trying to find an alternative. There's pkexec, which is quite secure but using pkexec often failed for certain applications- it just would not open them. Then there is the ///admin thing that no one quite remembers how it goes... I still don't, as you can see.
Opening apps using sudo is discouraged because it can corrupt .ICEauthority file and opens graphical apps as root while still using the Users Configuration files.

What we need is gksu back

And to do that, you can create an alias for pkexec that adjusts the authority and opens all GUI apps.
For those of you using the default bash for terminal, you can open your ~.bashrc file however you want.

sudo nano ~/.bashrc

Or open it from your home directory with your text editor. Add the following line to the bottom.

alias gksu='pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY'

Save and exit. Once done, in terminal, run
. ~/.bashrc

Note the space between the . and the ~
Hit enter. Wait a moment - then test opening Xed or Gedit in terminal with gksu (But without gksu):

gksu gedit

For those of us using something other than bash, replace bashrc with what you are using. In my case, it is zsh, so: I would paste the same alias line above at the end of ~/.zshrc, then in terminal run . ~/.zshrc

Works like a charm.

Source

4 Likes