Sayuj
Sayuj

Reputation: 7622

sshpass not working properly

I'm using sshpass to pass the password non-interactive on ubuntu 11.04.

when I use sshpass with scp

sshpass -p '123' scp [email protected]:/home/sayuj/examples.desktop ~/Desktop/

it works fine

but it doesn't work with ssh

sshpass -p '123' ssh [email protected]

What could be the problem and how do I fix it?

Upvotes: 8

Views: 31788

Answers (5)

Luis H Cabrejo
Luis H Cabrejo

Reputation: 316

Finally, I ended up using rsync instead of scp just because of the same problem. I have been forced to use this useful command because I'm backing up router configurations and data of computers connected to those routers. Routers use a very limited amount of linux commands, and this one is available on the models we are using. We tryied to use SSH keys but routers dont have permanent memory, once they reinicialize, all SSH keys get wiped out.

So the command for rsync is here with the -e option enabled, also I am using a 2222 port, the -p option allows you to change ports.

sshpass -p 'password' rsync -vaurP -e 'ssh -p 2222'  backup@???.your.ip.???:/somedir/public_data/temp/ /your/localdata/temp

You can protect even further, as I have done, replacing the password for a one-line file using a bash script for a multi-server environment. Alternative is to use the -f option so the password does not show in the bash history -f "/path/to/passwordfile"

If you want to update only modified files then you should use this parameters -h -v -r -P -t as described here https://unix.stackexchange.com/questions/67539/how-to-rsync-only-new-files

By the way, if you want to do the restore, just reverse the source by the target. Don't need to change much, from the same command shell you can do it reversing the order of target and source directories, make sure you have a user on the target with the same password to accept the rsync

Upvotes: 0

Alex Montoya
Alex Montoya

Reputation: 5099

Maybe do you need -o stricthostkeychecking=no like this

sshpass -p $PASSWORD ssh -o stricthostkeychecking=no user@domain "command1;command2;"

Upvotes: 15

Sridhar
Sridhar

Reputation: 1

You can use rsync as mentioned below:

rsync --rsh="sshpass -p 123 ssh -l sayuj" 192.168.1.51:/home/sayuj/examples.desktop ~/Desktop/

Upvotes: -1

Temujeen
Temujeen

Reputation: 36

I found a solution:

The problem is that the new version of ssh client still has and old version of sshpass (from 2008 not changed).

You can find the patch here

sshpass source

All that you need is just patch the sources (just 1 line add and 1 little change), compile, and install (don't forget to remove package before).

Upvotes: 2

mmm
mmm

Reputation: 1718

New sshpass version 1.05 works with the latest ssh client. It is included in the Ubuntu 12.04 Precise Pangolin.

For older Ubuntu (or other Linux distros) you can get the sources from:

http://sourceforge.net/projects/sshpass/files/sshpass/1.05/

untar with:

tar xvzf sshpass-1.05.tar.gz

build:

cd sshpass-1.05
./configure
make

and use the created binary sshpass.

Upvotes: 7

Related Questions