Rsync over SSH from an ant script with a password

I have a virtual machine running on my developer machine, and I need to rsync files to it over SSH via an ant build script to "deploy". In production, security is a concern, but I really don't care about secure SSH practices when communicating with a dev VM on my local machine.

I could have created a cert and installed it in my SSH keys, but that's a little annoying. I'd much rather just send my password to rsync via the ant script and call it a day.

(EDIT - If you reeeeally can't handle this question without an example, let's assume this server is outside my control, and their evil sysadmin refuses to allow me to sign in with an SSH key for whatever reason. Who knows? He's just crazy man!)

Is there any way to invoke SSH, or more specifically rsync in non-interactive mode, without editing your ssh config? In other words, just supply the password?


I happen to have already figured out a solution to this, but it wasn't very easy, so I wanted to share it.

Basically, I used a command line program called "expect" to fill my password into rsync's interactive mode. I also didn't want to have to write it up as a script, so I condensed it into a single command. This also works for ssh as well as rsync, if you need that for some reason.

Maybe there's a better way, but this seems to work fine.

192.168.64.131 is obviously my local VM's ip in the following. Replace login_name and login_password with your ssh login & pass.

expect -c 'spawn rsync -avz -e ssh ./ login_name@192.168.64.131:/var/www/auth/; expect "*?assword:*" {send "login_passwordr"; interact};'

Much easier and more secure to use an SSH key. An example is given in the following answer:

  • Ant, download fileset from remote machine
  • 链接地址: http://www.djcxy.com/p/60044.html

    上一篇: 无法通过SSH连接使用RSYNC守护进程

    下一篇: 使用密码的ant脚本通过SSH进行Rsync