This is what I plan to do:


sudo -i <<'EOF'
iptables-save | awk '/^[*]/ { print $1 } 
                 /^:[A-Z]+ [^-]/ { print $1 " ACCEPT" ; }
                 /COMMIT/ { print $0; }' | iptables-restore

I will save the above and call it cleariptables.sh. I will set it as executable.

It will be placed in a folder called bin in the following path: /home/cymbal/bin/

(where cymbal is the username)

I will create a shortcut to cleariptables.sh on the desktop. The contents of the shortcut will be:

[Desktop Entry]
Exec=gksudo /home/cymbal/bin/cleariptables.sh
Comment[en_US]=Flush iptables filters
Comment=Flush iptables script

Whenever I click on the desktop shortcut, I will be prompted to enter the password and the script will run.

Question: Clicking on the desktop shortcut prompts me for the password. As there is a sudo -i in the script, will I be prompted again for the password?


2 Answers 2


No, you should not be prompted for a password again. The script will be running as root due to the gksudo. In my experience, sudo never asks for password if you are already root (although I couldn't find this explicitly documented).

  • You are right. I was not prompted for a password again.
    – user66229
    Commented May 26, 2014 at 16:53

You can use NOPASSWD directive in your sudoers file.

Add this line to your /etc/sudoers file

your_login ALL = (root) NOPASSWD: /path/to/your/script

When editing this file, you should use the visudo command instead of a regular text editor. This will check for syntax errors before saving your changes.

  • Thanks for the tip. What does your_login represent? Is it my username?
    – user66229
    Commented May 25, 2014 at 22:48
  • 1
    Yes it is cymbal
    – Slyx
    Commented May 26, 2014 at 2:44
  • Thanks for the clarification. Now, if I add your recommended line to my /etc/sudoers file, will my username become root from that point onwards? I do not want that to happen. During Debian installation, I expressly chose not to allow log in as root.
    – user66229
    Commented May 26, 2014 at 3:48
  • 1
    No ! Only the given command is run as root. It's not a root login !
    – Slyx
    Commented May 26, 2014 at 3:52
  • 1
    But any files by your script, will have the root as owner :-)
    – Slyx
    Commented May 26, 2014 at 3:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .