#StackBounty: #bash #scripts #executable Make executable bash script run with sudo privileges?

Bounty: 50

Ubuntu 18.04 Gnome de.

I made a simple bash script file that flags my next reboot to choose the windows grub entry. For quick rebooting into windows straight from Linux DE.

The problem is I have to use dconf to modify executable files to ask, so I can click run in terminal where it automatically asks for password. Otherwise, just executing the file does nothing, bc it’s waiting for a password input.

Is there a way to run a bash script file like this with inherent sudo privileges so it doesn’t need to ask for a password?

EDIT (even though it’s directed at @waltinator, because comment formatting is atrocious):

So would


be the location and name of my bash script file? for example, my bash script file is named restart2windows and is located on my desktop:


so I would just need to add this line to /etc/sudoers (I’m still unclear on editing that file, using visudo, and whether I should edit sudoers.d as advised):

myusername     mymachinename = NOPASSWD: /home/myusername/Desktop/restart2windows

Would this be correct?


I tried editing sudoers via visudo:

sudo visudo

and added the line I suggested above, below the commented line:

#includedir /etc/sudoers.d

and then tried to run my bash script file from my desktop, and it did nothing. If I choose to run it in the terminal, the terminal is waiting for a password input.

Here is my bash script file contents, very simple:

sudo grub-reboot 2
sudo reboot now

Found this question here and it appears that I need to add sudo somewhere in there? I’m confused by that answer to that question because his line of code from the OP does not match the OP’s.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.