Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put sshpass command inside a bash script?

Tags:

bash

ssh

I am trying to run a sshpass command inside a bash script but it isn't working.

If I run the same command from the terminal it works fine but running it in a bash script it doesn't.

#! /bin/bash

sshpass -p 'password' ssh user@host command

I am aware of the security issues but its not important now.

Can someone help? Am I missing something.

Thanks

like image 502
rcsimoes Avatar asked Oct 10 '13 17:10

rcsimoes


People also ask

How do I run Sshpass?

Use sshpassSpecify the command you want to run after the sshpass options. Typically, the command is ssh with arguments, but it can also be any other command. The SSH password prompt is, however, currently hardcoded into sshpass .

Can I SSH in a bash script?

Bash script SSH is a common tool for Linux users. It is needed when you want to run a command from a local server or a Linux workstation. SSH is also used to access local Bash scripts from a local or remote server.

What is Sshpass command?

You can use the sshpass command to provide the password automation for ssh based login. It is a non-interactive ssh password auth tool. This tool is designed for running ssh using the mode referred to as “keyboard-interactive” password authentication, but in non-interactive mode.


1 Answers

Try the "-o StrictHostKeyChecking=no" option to ssh("-o" being the flag that tells ssh that your are going to use an option). This accepts any incoming RSA key from your ssh connection, even if the key is not in the "known host" list.

sshpass -p 'password' ssh -o StrictHostKeyChecking=no user@host 'command'
like image 62
Jotunn Avatar answered Sep 28 '22 09:09

Jotunn