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
BFranks
  • 55

1 Answers1

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.

  • 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