Can I include a password in my rsync call?

孤街醉人 提交于 2019-12-10 23:08:58

问题


I use rsync to update my static website. I currently cd to the local website directory, and run the rsync command, and then enter the password in the next line. I've saved my rsync call into a text snippet (such that _rs just expands to my call). Is there way to use something like a -p flag at the end and include the password too?

My call looks like this:

rsync -avzh -e ssh * foo@foo.org:"/home/foo/public_html/"


回答1:


One of option is use public/private key pair, see How to auto rsync with ssh passwordless

Or you can try use Expect




回答2:


Answering this with a direct answer to the question, may be useful in less secure scenarios.

#!/usr/bin/expect -f

set PASSPH "123456"
send_user "\n"
stty -echo

spawn rsync -apv -e ssh "/Volumes/Macintosh HD/Users/charliechaplin/test/" "charly@chaplin.com:/project/htdocs/site/"
expect "password:"
send "$PASSPH\n"
expect "#"


来源:https://stackoverflow.com/questions/12029140/can-i-include-a-password-in-my-rsync-call

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!