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