Results 1 to 10 of 33

Thread: Make executable bash script run with sudo privileges?

Threaded View

  1. #1
    Join Date
    Jan 2020
    Beans
    21

    Make executable bash script run with sudo privileges?

    EDIT:

    1) First off, yes, I'm aware that this is a bad security practice and I should not make a habit out of doing this, and I realize I should try to limit the scope of these privileges as much as possible.

    2) I've also read the sudoers manpages and visudo manpages, as mentioned in the askubuntu post.

    3) If any of you are askubuntu users, I've placed a bounty (my first) on my question there. So feel free to comment there if you have a suggestion to answer my question.



    (Original post below)
    __________________________________________

    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. Here it is:


    Code:
    #!/bin/bash
    sudo grub-reboot 2
    sudo reboot now

    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? I want to be able to double click the executable on my desktop or a shortcut to it, and have it execute without need for a password or prompt for password.

    bash script file is named restart2windows and is located on my desktop:

    Code:
    /home/myusername/Desktop/restart2windows
    So would I just need to add this following lime to the /etc/sudoers file via sudo visudo?:

    Code:
    myusername     mymachinename = NOPASSWD: /home/myusername/Desktop/restart2windows
    Last edited by bingbong6; 1 Week Ago at 12:58 PM.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •