Follow this Blog!

Mar 17, 2011

f Comment

How Do You Skip Password Prompt with 'Sudo' Command In Unix?

Amazon Whenever I execute a command with 'sudo' in Unix I always get a prompt for entering my password. How do I skip entering my password?

When you are writing a script and in that script would like to execute a command that requires elevated privilege, you'd have issues because you'd need to enter the password afterwords. Suppose the command you want to execute is:

sudo rm *
And your password is 'myPassWord' without quotes, then here's what you do:

echo myPassWord | sudo -S rm *
'-S' is the option provided by 'sudo' command that means it'll read the password from the standard input instead of the terminal device. That's why you can pipe your password via 'echo' and you'll be able to skip the password prompt this way.

Enjoy! Questions? Let me know!
Please leave a comment here!
One Minute Information - by Michael Wen
Find Michael on Google or Facebook
ADVERTISING WITH US - Direct your advertising requests to Michael