Linux – Ubuntu 10.04 using ssh without entering the password

bashlinuxpasswordsssh

I know questions like this have been asked before, and I have read them all (that I found).

The problem I have is that we have an embedded linux device that we can log into for debug purposes by doing the following:

ssh root@name

Then the password is anything (I usually just hit enter). I don't want to change anything on the embedded device/linux. But I do want to be able to (as part of my script) ssh into it.

My research has shown me that the following can be used (this is copied from another post):

#!/usr/bin/expect -f
spawn ssh user@my.server.com
expect "assword:"
send "mypassword\r"
interact

However with my version of Ubuntu (10.04) I don't have spawn or send commands. I was able to install the "expect" command with sudo apt-get install expect.

Does anyone have a solution? is it possible to install these commands, or is there another way to ssh and get past the "password" step?

Thanks 🙂

————- EDIT —————–

I think I am starting to understand the issue I am having. I have a script that starts with:

#!/bin/bash

Then later I am trying to do:

spawn ssh user@my.server.com
expect "assword:"
send "mypassword\r"
interact

I did not realise that you needed explicitly the:

#!/usr/bin/expect -f

At the start of the script. so I have had to move my code into a seperate file which contains only and exactly:

#!/usr/bin/expect -f
spawn ssh user@my.server.com
expect "assword:"
send "mypassword\r"
interact

… sorry for the mis-understanding on my part, but people answers helped me to twig what I was doing. This is not quite ideal for me as I wanted to pass parameters in to open different ssh connections and I can't pass in parameters to this script starting with "expect -f"
🙁

Best Answer

I think you're trying to run your script as a shell script. After installing expect, run your script like this:

expect -f scrip.exp

If you can't install expect as a normal user, try installing its binaries in one of your directories in $HOME e.g. $HOME/opt/ and call expect from there, although it would depend on your system on how you could manipulate LD_LIBRARY_PATH to add another directory for searching dynamic libraries.

An example of embedded expect:

#!/bin/bash

USER=$1
SERVER=$2
PASSWORD=$3

expect <<EOF
spawn ssh "${USER}@${SERVER}"
expect "assword:"
send "${PASSWORD}\r"
interact
EOF

Run with

bash script.sh user server password
Related Question