running a script using su - without prompting password

hi guys, is there any way to run a script using su - without prompting a password?
ex: su - $APPSUSERNAME/$APPSUSERPASSWORD stop_apps.sh

my purpose here is to run a script with current dbuser. thanks in advance.

edit /etc/sudoers

and add:

username ALL=(ALL) NOPASSWD: ALL
1 Like

great it works! thanks itkamaraj.
I add the following line and specify only the specific script.

dbuser ALL=(appuser) NOPASSWD: /data/erpp/scripts/stop_apps.sh

You can log or execute commands as another user using ssh:

ssh host -p 22 -l remote-user -q "command args"

To bypass password, generate a key par for the guest account:

ssh-keygen -t rsa

And append the contents of ~/.ssh/id_dsa.pub in the guest account to the file ~/.ssh/authorized_keys in the host account in the remote server.

For troubleshooting look at /var/log/secure with a privileged user.

Editing "/etc/sudoers" as below is a security risk, as "username" can impersonate anyone, even root.

username ALL=(ALL) NOPASSWD: ALL