Ubuntu – I need an equivalent of gksu in 18.04

gksurootsudo

I've read a lot of threads about gksu being removed from many Linux flavours, including Ubuntu 18.04. Many state that gksu is an abomination and no user should ever need to use anything like it. I have 2 examples where, as far as I know, I must have something that allows me to run as root (not just for editing files).

First, I have a need to start mysql only after an encrypted folder is opened on (GUI) command. This means having a script run by the encryption system that starts the mysql service. That has to be done as root, so I use gksu in that startup script which asks me for a password. How else can I start a service from a GUI system?

I also run Ubuntu system backups as root, otherwise many system files can't be backed up. So the desktop file uses gksu to start the backup.

pkexec looks complicated, needing policy files. Is that the only alternative, and if so, why is it any safer?

Other answers to similar questions don't seem to address individual issues that people have now that gksu is no more (or harder to find…). I think such questions from non-expert users would benefit from more detailed answers. I now have some, and so would like to answer my own question.

Best Answer

I found this command

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

in this page

After running the alias command:

gksu /path/to/script.sh

It will ask you for a password like normal.

You will need to add the alias to the end of ~/.bashrc in order to keep the gksu command persistent on reboot.