Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
#shell script
sudo ls

When I execute it, script asks for the password. I would like to add my password as part of the script or argument. How can I do it?

share|improve this question
See if… helps – user25656 Jan 11 '14 at 2:36
echo password | sudo -S command

So you pipe your password to sudo, and the -S command makes sudo read your password from the standard input instead of the terminal.

share|improve this answer
Of course, this is a big security flaw, as you store your password in plain text. – morphheus Jan 11 '14 at 2:54
Well then this will help you… – Qasim Jan 11 '14 at 3:08
If you want a different syntax: sudo -S <<<'password' command – Presbitero Jan 11 '14 at 13:47

Here is a small script. It will ask your password on a pop-up window when you execute the script.

pop-up window asking password


ENTRY=$(zenity --password)

if [ $ENTRY ]; then
    echo -e "$(echo $ENTRY)" | sudo -S date
    echo "abort"
sudo ls

And it is quite safe as it is not storing your password anywhere or allowing to display the characters while you input your password.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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