Sending ssh password in a script

Is there any way to send password in a sh script, to establish a ssh connection with the remote server, without having shared the public key?

The command I'm currently using is in my script is

!#/bin/sh

...

ssh -l user remotehost "ls -l"

I have shared the public key of the local server with the remote server, therefore I will not be prompted for the password when I execute this script. Is there any way of sending the password in the script itself?

Please do not suggest 'expect' scripts. I do not have expect installed. Am using the default shell that comes along with the server.

Unless you code the script in something like the "expect" program's scripting language the answer is "no".

I installed " Expect" on my Sun box, with help from some guys here on this form, I got the SFTP script working. It works great. You should reconsider and install "Expect".
or you can use Perl. Once again, you need to install Perl.

If you have placed the client's public key on the box being ssh'd too, then there's no need for a password prompt of any kind. However, if the key requires a passphrase, which is prompted for locally, then you do get the idea I suppose of a prompted password. But it's just an "unlock" to use your client private key.

So... I'm guessing that your key has a passphrase associated with it? You may want to consider creating one without a passphrase. Also, ssh is pretty flexible... so if not having a passphrase is disconcerting, you can associate a remote command with the public key so that the desired thing is executed anytime somebody comes across using the passphraseless key.

On a Linux box do a man sshd and search for command= if you want to setup a passphraseless key that does some remote command instead of a shell. When a client has multiple identities you have to specify which key (identity) to use when you do the ssh client call.

Hope that all made sense.... :slight_smile: