0

can someone tell me, how I can run a bash script on a remote host with sshpass?

Is this possible?

Thanks for your help & best regards

Pascal
  • 105
  • 1
  • 3
  • 7
  • 1
    `sshpass -p 'password' ssh user@host "ls; whois google.com;"` – JNevill Apr 18 '17 at 18:40
  • Hi, I have tried to run the following command: sshpass -p SecurePW$ root@domain.com "sh /home/root/script.sh" The command does not work: "sshpass: Failed to run command: No such file or directory" – Pascal Apr 19 '17 at 11:19
  • Is `sshpass` in your `PATH`? Try `type sshpass` – Robert Seaman Apr 19 '17 at 14:58
  • here explain the same question https://stackoverflow.com/questions/19302572/how-to-put-sshpass-command-inside-a-bash-script – Alex Montoya Jul 10 '18 at 19:15

1 Answers1

1

First you have to install sshpass.

sudo apt-get install sshpass

Now try the following command this worked for me.

sshpass -p pass ssh -t user@192.168.XX.XXX 'ls; bash -l'

Remember to replace 'pass' with the server password and 'user' with the username.(also put correct host address).

suppose password is student and username is student and host address is 192.168.118.104 Then your command looks like this

sshpass -p student ssh -t student@192.168.118.104 'ls; bash -l'

SRIDHARAN
  • 1,196
  • 1
  • 15
  • 35