Forcing another user to run a shell script (su)

I'm trying to use su (as myuser) to force another user (theuser) to run a shell script (thescript.sh):

su theuser -c /home/theuser/thescript.sh

However I'm running this from another script, and it is asking for theuser's password. I would rather avoid displaying it in the file (using echo <password> | <su command>).

I have searched and seen this asked a lot before, and the solution was to use:

myuser ALL=(ALL) NOPASSWD: ALL

at the end of my sudoers file, however with that it is still asking for the password.

unless their root this wont work.

run it like this as mysuser

sudo -u theuser /home/theuser/thescript.sh

As frank_rizzo points out you need to use sudo.

The entry you added to sudoers allows myuser to run any command as anyuser without password.

You should lock this down a bit, the following only allows myuser to run /home/theuser/thescript.sh as theuser:

myuser ALL=(theuser) NOPASSWD: /home/theuser/thescript.sh