Provide password to ssh command inside bash script, Without the usage of public keys and Expect


I want to use SSH inside a script, but this script is not going to be executed on my machine.

In my implementation there are two limitations.

  • I can not work outside shell's standards,therefore i can not use expect because i do not know if it will be available on this machine.
  • I can not expect that this machine will have public keys for the SSH.

What are the possible options-solutions ?

How can i provide ssh with the requested password with an automated and secure way without adding extra dependencies?

Will it be possible to provide the password inside the script?

Thank you all in advance :)

This question is tagged with linux bash shell ssh

~ Asked on 2013-06-05 10:06:34

The Best Answer is


Install sshpass, then launch the command:

sshpass -p "yourpassword" ssh -o StrictHostKeyChecking=no [email protected]

~ Answered on 2013-06-05 12:48:50


For security reasons you must avoid providing password on a command line otherwise anyone running ps command can see your password. Better to use sshpass utility like this:


export SSHPASS="your-password"
sshpass -e ssh -oBatchMode=no [email protected]

You might be interested in How to run the sftp command with a password from Bash script?

~ Answered on 2013-06-05 13:01:30

Most Viewed Questions: