Use sudo without password prompt


To run any command as root user sudo is used.

By default when we run any command with sudo, it asks for password.

Whenever we write a script to automate, by any chance if we are using sudo in script, automation is not possible.

To disable password authentication for sudo we need to edit /etc/sudoers file.

Let’s say if we have user with name test, to disable password authentication for test user following line need to be added in /etc/sudoers file.

test ALL=NOPASSWD: /etc/init.d/httpd restart,/etc/init.d/httpd start,/etc/init.d/httpd stop

Above line will disable password prompt for following commands:

sudo /etc/init.d/httpd restart

sudo /etc/init.d/httpd start

sudo /etc/init.d/httpd stop



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s