I would like to launch a Gnome application with root privileges at login.

I have tried adding a script to launch using update-rc.d myscript.sh defaults.

It looks like the application does launch, but it is no longer there by the time the gnome gui arrives.

How can I do that?


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:

  1. 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 try sudo -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).

  2. Auto-launch your application via the standard "Startup Applications", calling sudo /path/to/command

And that's it.

  • If put username ALL=(ALL:ALL) NOPASSWD:/path/to/command in /etc/sudoers, sudo fails with a parse error. ALL= NOPASSWD:/path/to/command seems to parse, but asks me for the password when I run the command.
    – benlad
    Apr 3 '12 at 12:18
  • 1
    So, it seems "username ALL=(ALL) NOPASSWD:/path/to/command" must be last in the sudoers file and also "username ALL=(ALL:ALL) NOPASSWD:/path/to/command" does not work with Ubuntu 8.04.
    – benlad
    Apr 3 '12 at 15:29

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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.