I'm using sshpass to pass the password non-interactive on ubuntu 11.04.
when I use sshpass with scp
sshpass -p '123' scp sayuj@192.168.1.51:/home/sayuj/examples.desktop ~/Desktop/
it works fine
but it doesn't work with ssh
sshpass -p '123' ssh sayuj@192.168.1.51
What could be the problem and how do I fix it?
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).
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.
Maybe do you need -o stricthostkeychecking=no
like this
sshpass -p $PASSWORD ssh -o stricthostkeychecking=no user@domain "command1;command2;"
Finally, I ended up using rsync
instead of scp
just because of the same problem. I have been force to use this useful command, because Im backing up routers configurations and data of computers conected 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 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. Dont need 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
You can use rsync
as mentioned below:
rsync --rsh="sshpass -p 123 ssh -l sayuj" 192.168.1.51:/home/sayuj/examples.desktop ~/Desktop/