I want to set up an RSync job that would connect through SSH.
I have my computer ( backup@myhost ) and the remote host ( test@remhost ) and I need to backup the folder ~/something with all it's contents. The ssh user test only has READ access to all files and folders in the ~/ folder. I want to use rsync to copy the test@remhost:~/something folder to the backup@myhost:~/bak folder.
For this purpose I use the following command via BASH on Ubuntu 11.10 (Oneiric):
rsync -avz -e ssh test@remhost:~/something/ ~/bak/
After hitting enter I get this:
test@remhost's password:
I type the password and the rsync works.
I want to make the above command to automatically input the password and pass it as a parameter or to input it automatically and start the job.
I tried executing rsync -avz -e ssh test:password@remhost:~/something/ ~/bak/
but it still asks for the password and it's annoying.
I don't want to hear about any kind of keys (RSA,DSA or any other). I just want a simple command that would log me in and do the job.
EDIT: A possible scenario could be, if public key authentication is disabled and you can't change this. E.g. if you use OpenSSH, you'd need root privileges on the server in order to edit the file sshd_config
and to add PubkeyAuthentication yes
.
EDIT: This is what finally worked for me:
sshpass -p 'sshpassword' rsync --progress -avz -e ssh test@remhost:~/something/ ~/bak/
Please note that this method is not considered secure as it sends the password in plain text and it's vulnerable to man-in-the-middle attacks. It is advised to use the key athentication for a stronger security.
maybe try sshpass.
seems simple enough to use... it's available through apt as well.
I was looking for something like this before I copied my keys around, but since I've got my key everywhere I need already anyway, I haven't taken the time to try this.
Do note the disclaimer on that tutorial there regarding the visibility of your password though.
For everyone who needs to do this:
A variation on your solution which is more secure to security threats is to store your password in a file with tight permissions and use the
-f
flag withshpass
:The difference is that listing the running processes will not show your password in the command line, it will now only show the path to the file in which your password is.
I can't imagine any situation where public-key authentication without passphrase wouldn't be the better solution for autmated ssh/rsync logins.
Anyway
expect
should be a way to achieve what you want to do. You can't pipe the password to ssh, but this is something very similar. How to do so, is answered here at stackoverflow.I found that sshpass works, but since the termanal says
SSHPASS read: Enter passphrase for key '/home/ubuntu/.ssh/id_rsa':
you need to run it something like this:Where
-P
specifies which prompt to look for I found that out by runningsshpass -v
and finding out its looking for the phrasepassword
which isn't there.the first thing is do ssh without
passowrd/bypass
the password login, as u can see we can usessh-copy-id -i ./ssh/id_rsa.pub
to target machine.After that test the machine Can be remotely by ssh without password, then rsync in on the way next of course from local machine into
target/server
machineThis also works:
ie. passing
sshpass
in--rsh
instead of in front ofrsync
This method alongside with the usage of the
SSHPASS
environment variable is described in the Examples section of the manual:https://www.freebsd.org/cgi/man.cgi?query=sshpass&sektion=1