kdesudo -u user kate new-file
^ opens text file in current directory. Ok. That’s what everyone is used to?
pkexec -u user env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY kate ./new-file
^ open text file in home folder even though it should be current folder because I was using
So what other options do we have…?
Notwithstanding the earlier warning, it is possible to use sudo with graphical apps provided you add the -H flag. This flag is critical: it properly sets root to its own environment instead of improperly inheriting the user’s environment. Use of the -H flag is mandatory. Failing to use this flag may corrupt critical system files and prevent you from logging in.
With sudo -H almost any graphical app can be launched under root within any 'buntu flavour. This includes each flavour’s default graphical editor and file manager.
An appreciable danger with sudo -H is that the -H flag is easy to forget. And all it takes is one omission for the damage to be done.
Omission of the
-H flag could be prevented. We could invent our own wrapper and have users use that.
sudo -H kate
^ results in more weirdness.
Executing Kate with sudo is not possible due to unfixable security vulnerabilities.
Please note that many websites and old threads advise the use of gksu. However, such search results are obsolete. gksudo has not been updated for years and is not even available in Bionic (18.04) and higher. gksu has been replaced by pkexec, but even pkexec is being deprecated by the mainline Ubuntu developers. They have taken the position that file manipulation and editing under root should be restricted to the command line.
“manipulation and editing under root should be restricted to the command line.” - Very bad usability.