Ubuntu – How to run .desktop icon from sudo


I have created a desktop icon for the gddccontrol, but to run it I need to execute it from sudo. Is there a way to run a command from the desktop icon like,

sudo -pPASSWORD gddccontrol

so it won't ask me for the password in the terminal?

I just want click and run it with sudo permissions.

[Desktop Entry]
Comment=gddccontrol ddccontrol
Exec=sudo -pPASSWORD gddccontrol

When I run the icon from the terminal with the following Exec command it works good, but it doesn't work in Launcher 🙁

Exec=echo mypasswd | sudo -S gddccontrol

Best Answer

NEVER EVER use your password, stored in a .desktop file. It is terribly unsafe.

Furthermore, you cannot run complicated commands in a .desktop file just like that, but that is another subject.

What to do

You have a few options:

  1. Add gddccontrol to the sudoers file, as explained e.g. here. This can be done if you are sure the application cannot be used to do maliceous things.

    Then use

    Exec=sudo gddccontrol

    in the Exec=-line

  2. Another option is to replace the Exec= line by:

    Exec=gksu gddccontrol

    In this case, once you click the icon, you will be prompted to enter your password via gui.
    You possibly need to install gksu:

    sudo apt-get install gksu