Rsync and SSH

Any Linux gurus out there?

I’m trying to write a Bash shell script that would synchronize a bunch of files on two computers. The script uses rsync over SSH.

My question is… is there any way to ask the user to input his SSH password just once, store it in a variable, and then use it for all subsequent rsync operations (until the script finishes)? I guess the problem is that I can’t specify the password as part of the SSH command (it only takes user@host). Can the script somehow wait for the SSH password prompt and then provide the password?

I looked into rsync’s password options, but those only work with the rsync protocol and not with SSH.

Thanks in advance if anyone can answer this.

Look into ssh-agent. The idea is that you have a passphrase you initially set up with ssh-agent, then you use ssh-add, give it the passphrase, and subsequent ssh calls do not require any password. I use usually use it in an initial shell, which I launch various programs from. none of those programs will need to request a password for any ssh access.

Yes, I think you want to use ssh-agent and ssh-add (though I’ve never used them in combination with rsync myself). This site gives some more information. Since you mention scripting, you might also want to look into expect, which allows you to put interactive stuff in your scripts.

I looked into ssh-agent, but I was hoping this could be done without having to store private keys on the machines.

But expect is exactly what I was looking for. That’ll make things much easier. Now if only I could find a way to have the bash script output an expect script and then run it.

Thanks to both of ya!