0

So I am running Linux Mint 17.2. I have a bash file I would like to run in terminal to login via SSH into my other mint 17.2 server. I am able to do this manually no problem, but when I try using the following script, it attempts to connect to the server, but then it just sits there at the password prompt.

#!/bin/bash
ssh mediaserver@mediaserver
expect "pasword:"
send "password\r"

not sure what to do here. Online help gets me no where so far.

amc
  • 7,022
  • 7
  • 39
  • 51
nomad12321
  • 1
  • 1
  • 1
  • 1
  • 4
    you should use ssh keys instead of passwords. see https://askubuntu.com/questions/46930/how-can-i-set-up-password-less-ssh-login – amc Nov 12 '15 at 03:07
  • 3
    Possible duplicate of [How to get response from ssh command using expect](http://askubuntu.com/questions/389694/how-to-get-response-from-ssh-command-using-expect) – Jakuje Nov 12 '15 at 08:14

1 Answers1

1

There is a package called sshpass that does what you want.

sudo apt-get install sshpass

Once it's installed, you can put into your script the following:

sshpass -p 'password-here' ssh mediaserver@mediaserver

Of course, it's generally not good practice to put a plain text password into a script or into source code. That said, this does exactly what you are asking.