When I google “gksu gedit” one of the top entries (How to run gedit and nautilus as root) advises that gksu
usage is frowned upon:
gksu hasn't been updated since 2009 and is not recommendedany more. In fact, Ubuntu no longer ships with gksu by default (though it may be installed for many of you, because some apps still depend on it) and it may even be completely removed at some point.
A link to AskUbuntu (Why is gksu no longer installed by default?) suggests pkexec
should be used instead but doesn't provide clear and concise steps to do this.
How can I use pkexec within a new wrapper shell script called gsu
that supports both gedit
and nautilus
?
I feel a wrapper script called gsu
is most appropriate because my "muscle memory" is to type gksu
all the time and I don't want to have to type pkexec
instead.
Additionally I would like those pesky gtk
warning messages to disappear. Also I would like the terminal prompt back right away instead of waiting for editor or file manager to end.
AU Duplicates: I've searched many Q&A but none are asking (or offering how to) give a complete solution for gsu
wrapper script to call pkexec
AND install all necessary policy kits AND get rid of pesky gtk warnings AND get terminal prompt back right away... All in one answer.
sudo wget ... -O /usr/share...
directly, instead of downloading to/tmp
and then copying? 2. If those rules will be in 17.04, they will be available in Launchpad, straight from Ubuntu's sources. Why not download from there instead of copying from $RANDOM_GITHUB_REPO? 3. Why would you quote$1
inCOMMAND="$1"
, and then not quote$COMMAND
when callingpkexec
? 4. Why not justpkexec "$@"
in that script? 5. In fact, why not just dopkexec gedit ...
directly instead of this script, now that the rules are installed?wget
with your ideas. I pickedgsu
overpkexec
because it's easier to remember coming off ofgksu
background. Also to get benefits of a wrapper script. Down the road I might modify it to log every file edited with date and time to /var/log/gedit history file or something similar. I'll reply to your other questions later after work. – WinEunuuchs2Unix Nov 10 '16 at 12:10pkexec
calls are logged, just likesudo
commands are logged. – muru Nov 10 '16 at 12:12gsu
wrapper script redirects the pesky gtk warnings to /dev/null without having to setup root shares. The wrapper also returns the command prompt immediately after pkexec starts. I'm not sure what future enhancements will be put into the wrapper, ie backing up source file and running diff to new saved file, but the flexibility is there. – WinEunuuchs2Unix Nov 10 '16 at 12:41alias gksu='pkexec'
. That won't redirect errors but you really don't want to redirect them. What if there's an actual error and not just gtk warnings? – terdon Nov 10 '16 at 14:38