0

I want to run an executable file as root by clicking an icon. I have the following desktop file (test.desktop) in place:

[Desktop Entry]
Version=1.0
Name=Test Program      
Comment=Open test program
Exec=sudo taskset -c 7 /home/username/Desktop/folder1/test_program %f
Icon=/home/username/Desktop/folder1/image.png
Terminal=true
Type=Application
Categories=Utility;Application;

This works, but each time I click the icon it requires me to enter my password, which is growing tiresome. I want this one icon to execute this one program program as root without a password prompt. I do not want to disable the password prompt for all sudo commands.

test_program above is an executable which requires root status to run correctly.

Further, if I change the Exec= line above to

Exec=gksudo -k -u root taskset -c 7 /home/username/Desktop/folder1/test_program %f

the program doesn't actually run, but rather opens terminal then closes terminal immediately.

How can I make this run as root without putting my password in each time?

Requested Edit #1: My edited sudoers file is given below.

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
ALL     ALL=NOPASSWD: /home/username/Desktop/folder1/test_program

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d
  • 1
    Use expect askubuntu.com/questions/689001/… – Panther Aug 16 '16 at 19:26
  • 1
    «it requires me to enter my password» That means it works. Are you asking for password-less sudo? That would be a different question (likely duplicate of existing questions on this topic). – Andrea Lazzarotto Aug 16 '16 at 19:51
  • @AndreaLazzarotto, your comment may help, but it isn't exactly what I want. I want this one icon to execute this one program program as root without a password prompt, not passwardless sudo across the board. @bodhi.zazen, thanks for the feedback. I will look for a tutorial on expect. It is definitely foreign to me. – BFranks Aug 17 '16 at 14:23
  • 2
    I see. It can be done per single command, or for a selection of commands. See here: askubuntu.com/a/72272/271 – Andrea Lazzarotto Aug 17 '16 at 14:32
  • 2
    Possible duplicate of How to allow execution without using sudo? – Andrea Lazzarotto Aug 17 '16 at 14:32
3
ALL     ALL=NOPASSWD: /home/username/Desktop/folder1/test_program

This is not the command you are trying to run as sudo. The command is:

taskset -c 7 /home/username/Desktop/folder1/test_program

(If you click on the launcher, the %f will be empty and you might as well remove it)

Therefore, you need to correct the sudoers file, but keep in mind that you need to use absolute paths as pointed out in this answer:

ALL     ALL=NOPASSWD: /usr/bin/taskset -c 7 /home/username/Desktop/folder1/test_program

As a side note, this setting enables every user to run taskset with the given argument with sudo. This might or might not be what you want.

| improve this answer | |
  • This edit actually made things worse. When I added taskset -c 7 to the sudoers file as you suggested, not only does visudo think this new line is a typo, but clicking the icon no longer launches terminal at all. – BFranks Aug 17 '16 at 15:47
  • 1
    @BFranks sorry, I overlooked the «use absolute paths to the program you are trying to use» in the answer we were talking about. Let me update my answer. – Andrea Lazzarotto Aug 17 '16 at 15:50
  • NICE WORK ANDREA!! Thank you! Works flawlessly. – BFranks Aug 17 '16 at 15:53

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.