Sign up ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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.

share|improve this question
You won't get any answers if you tell people not to tell you the answer. –  Mike Scott Jan 5 '12 at 11:32
This is pointless. What's the problem with the key authentication? If key based authentication is configured, then from that point you have only a simple command which does the job, automatically, exactly that you want. So I can't see what's the problem with this. Storing the password somewhere to specify it "automatically" is one of the biggest security hole I can imagine, what's the point to do that? –  LGB Jan 5 '12 at 12:01
I don't need anyone to give me lectures on security. I already know the implications. I just have to leave everything on the server as is and not change anything. For your Information I already tried that with keys and it still asks me for the password therefore your argument is invalid! –  Sorin-Mihai Oprea Jan 5 '12 at 12:10
No, for good reasons there is no such parameter by default. Look at Migs' answer if you want such a parameter. –  lumbric Jan 5 '12 at 12:27
@Sorin Mihai Oprea: Well, if it does not work for you, it's bad? Interesting. For your information: as an internet system engineer working at an ISP we use key based authentication with ssh on more than 100 servers. It works for us, interesting. Don't call something bad just because you don't understand how it works and how it must be configured. If you are right, it would not work for anyone which would attract some attention as a major ssh server implementation bug :) So my agrument is not invalid, just you can't configure it well for some reason. It's not the same, sorry. –  LGB Jan 5 '12 at 12:53

4 Answers 4

up vote 12 down vote accepted

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:

sshpass -p 'sshpassword' rsync --progress -avz -e ssh test@remhost:~/something/ ~/bak/
share|improve this answer
Thank you so much! This actually helped me! –  Sorin-Mihai Oprea Jan 5 '12 at 13:36
You are most welcome. While I agree with the rest of the folks here that public-key-authentication is the best solution for this matter, sometimes alternative methods are needed, so long as we're aware of the trade-offs when using alternatives. –  Migs Jan 5 '12 at 13:41
Indeed ... but that's why it's called open source right? Multiple flavors ... same result! –  Sorin-Mihai Oprea Jan 5 '12 at 14:03

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 with shpass:

sshpass -f '/home/me/.password' rsync --progress -avz -e ssh
test@remhost:~/something/ ~/bak/

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.

share|improve this answer

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.

share|improve this answer
Thank you for the suggestion but I actually found sshpass a lot more simpler! –  Sorin-Mihai Oprea Jan 5 '12 at 13:38

A perfect example is automated login to customer systems where you are allowed to login via password, but pubkey is disabled for security reasons (we're talking 100s of systems with different OSes, pubkey management is not very effective for them - think time limited access enforcement, workforce retention, ...).

I have about 30 of such customers and the arrogance of openssh community insisting on "Not another one of those! You don't understand, just use pubkey, it's more secure anyway, you'll thank us later." is very frustrating.

I understand the security implications, but pubkey is simply not an option sometimes.

sshpass helps, but it gets quite cumbersome with proxying through several systems, using rsync/scp/ssh and having to always prefix the command, etc...

Being able to somehow store passwords in a file and reference them from ssh_config is something I'd be happy to pay money for. SSH can even enforce some crazy privileges on that file to discourage laymen from using this and push them gently towards pubkey (which I agree is generally a better idea).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.