I have a bash script that accepts exactly 3 arguments and I have created a web interface in PHP to run this script on a remote server. The user just enters username host and password of the remote server.
I found this command to execute bash script on remote server:
ssh root@host 'bash -s' < script.sh
But this command prompts for a password and also doesn't use any arguments. But I need something that can be run non-interactively.
Something like:
ssh root@host -password="password" 'bash -s' < script.sh
Best Answer
Make sure that you have read security considerations
Install
sshpass
it's a tool for non-interactive ssh password authentication.You can use it like:
Then use it like this to run your script with its arguments:
If it didn't work then what I suggest is to use
scp
and move your script to remote server, then run your command and remove the script:Security considerations [man sshpass]