How do I launch a GUI application as root on user login?
Solution 1:
Running graphical things as root is a bad idea for security but I'm going to assume you know that and that you have exhausted any other methods. You need to do two things:
-
Allow your user to run the command via
sudo
without a password by editing/etc/sudoers
. You can find a brief explanation here but you're looking for something like this:username ALL=(ALL:ALL) NOPASSWD:/path/to/command
Obviously replace the
username
and/path/to/command
with real values, stick that in there and then trysudo -k /path/to/command
(the-k
just means it'll ask for your password if it doesn't know any better - it won't ask if your sudoers edit was correct). Auto-launch your application via the standard "Startup Applications", calling
sudo /path/to/command
And that's it.
Solution 2:
You could try to create a custom application launcher (.desktop
file) with gksudo <command>
as command to run, and add that laucher to the autostart settings (System - Settings - Autostart
or Startup
). Another way would be to put the .desktop
file directly into ~/.config/autostart
or (for all users) /etc/xdg/autostart
.
More on *autostart*ing applications in Gnome's documentation;
HowTo add an autostart application in Gnome 3;
similar for Gnome 2.