I’m using Amazon Linux. If I login as my “otheruser” user, and create a script, test.sh, with this text
sleep 5 ; sudo reboot now
I can login and run the script like so …
[davea@mydevbox ~]$ sudo su - otheruser
[sudo] password for davea:
Last login: Wed Apr 20 21:18:48 UTC 2016 on pts/0
[otheruser@mydevbox ~]$ sh test.sh
[otheruser@mydevbox ~]$
Broadcast message from davea@mydevbox.springboardonline.org
(/dev/pts/0) at 21:19 ...
The system is going down for reboot NOW!
However if I change the contents of the script to be
sudo service jboss restart
and then I run the script, I’m prompted for a password …
[davea@mydevbox ~]$ sudo su - otheruser
[sudo] password for davea:
Last login: Wed Apr 20 21:09:03 UTC 2016 on pts/0
[otheruser@mydevbox ~]$ sh test.sh
[sudo] password for otheruser:
I would like the second sequence to be like the first in that I’m not prompted for a password the second time. How can I do this?