Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.
==============
#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
1  
See if askubuntu.com/questions/52212/… helps –  user25656 Jan 11 at 2:36
add comment

2 Answers 2

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 at 2:54
1  
Well then this will help you askubuntu.com/questions/291520/… –  Qasim Jan 11 at 3:08
    
If you want a different syntax: sudo -S <<<'password' command –  Presbitero Jan 11 at 13:47
add comment

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

#!/bin/bash

ENTRY=$(zenity --password)

if [ $ENTRY ]; then
    echo -e "$(echo $ENTRY)" | sudo -S date
else
    echo "abort"
fi 
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
add comment

Your Answer

 
discard

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.