This question already has an answer here:

I have a shell script using some sudo command. When I run this script from terminal - it asks me for password and runs with any problem. But when I try to run executable shell script form GUI (double click) it does not ask me for password - so does not work.

Example of my shell script:

c1=$(dmidecode -t 4 | grep ID | sed 's/.*ID://;s/ //g' | sha1sum | awk '{print $1}')

How to run script from GUI and pass all sudo commands with no problem?

marked as duplicate by muru command-line Jun 22 '16 at 10:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • TL;DR: use gksudo or pkexec. – muru Jun 22 '16 at 10:18
  • @JonasCz the dupe is about getting a GUI password prompt, not running GUI applications - if OP wants to avoid having a password prompt at all, they should ask that – muru Jun 22 '16 at 10:27

You can pass the password to sudo from the standard input, like this:

echo 'yourpassword' | sudo -S yourcommand

Using -S tells sudo to read the password from stdin, which comes from the echo 'yourpassword' bit.

You could also edit visudo, so that sudo will never prompt for the password, either only for your specific comand, or always.

Warning: storing your password in plain text is an extremely bad idea

  • Great it works well for me. Thank you so much. – Geroge Jun 22 '16 at 10:21
  • 5
    Storing admin passwords in PLAIN TEXT??? Are you mad? – Byte Commander Jun 24 '16 at 7:25
  • Bad advice. Seriously. You -never- ever provide a password to the process list. This is asking for that system to get compromised. The 2 answers in the dupe linked should be used. – Rinzwind Jun 24 '16 at 7:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.