sshpass not working properly
Asked Answered
E

5

8

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?

Ethology answered 28/6, 2011 at 6:26 Comment(0)
O
2

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).

Orangy answered 6/7, 2011 at 13:22 Comment(1)
I'm experiencing the same hang on CentOS 6.7 using version 1.05 which is newer than the patched version mentioned - anybody else find the same?Frankforter
E
15

Maybe do you need -o stricthostkeychecking=no like this

sshpass -p $PASSWORD ssh -o stricthostkeychecking=no user@domain "command1;command2;"
Exemplification answered 11/7, 2018 at 0:34 Comment(0)
T
7

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.

Tiemroth answered 6/6, 2012 at 0:17 Comment(0)
O
2

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).

Orangy answered 6/7, 2011 at 13:22 Comment(1)
I'm experiencing the same hang on CentOS 6.7 using version 1.05 which is newer than the patched version mentioned - anybody else find the same?Frankforter
M
0

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

Margarite answered 16/12, 2018 at 17:48 Comment(0)
A
-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/

Attraction answered 25/7, 2013 at 15:20 Comment(1)
The OP says that he can successfully copy files using scp. It is opening an SSH session that he can't do.Menarche

© 2022 - 2024 — McMap. All rights reserved.