How do I launch a GUI application as root on user login?

35,270

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:

  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.

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.

Share:
35,270

Related videos on Youtube

benlad
Author by

benlad

Updated on September 18, 2022

Comments

  • benlad
    benlad over 1 year

    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?

  • benlad
    benlad about 12 years
    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
    benlad about 12 years
    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.