# Rsync and SSH

**URL:** <https://boards.straightdope.com/t/rsync-and-ssh/338504>\
**Category:** Factual Questions\
**Created:** [January 5, 2006, 1:45am UTC](https://boards.straightdope.com/t/rsync-and-ssh/338504 "2006-01-05T01:45:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [January 5, 2006, 1:45am UTC](https://boards.straightdope.com/t/rsync-and-ssh/338504/1 "2006-01-05T01:45:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Avumede](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/avumede/32/7235_2.png) [@Avumede](https://boards.straightdope.com/u/Avumede)\
**Post date:** [January 5, 2006, 2:25am UTC](https://boards.straightdope.com/t/rsync-and-ssh/338504/2 "2006-01-05T02:25:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Digital\_Stimulus](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Digital\_Stimulus](https://boards.straightdope.com/u/Digital_Stimulus)\
**Post date:** [January 5, 2006, 12:43pm UTC](https://boards.straightdope.com/t/rsync-and-ssh/338504/3 "2006-01-05T12:43:20Z")

</div>

Yes, I think you want to use _ssh-agent_ and _ssh-add_ (though I’ve never used them in combination with _rsync_ myself). [This](http://acd.ucar.edu/~fredrick/mpark/ssh/rsa-unix.html) 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.

---

<div class="post-metadata">

**Author:** ![Reply](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/reply/32/15952_2.png) [@Reply](https://boards.straightdope.com/u/Reply)\
**Post date:** [January 5, 2006, 7:21pm UTC](https://boards.straightdope.com/t/rsync-and-ssh/338504/4 "2006-01-05T19:21:33Z")

</div>

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!
