2

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?

DougW
  • 28,776
  • 18
  • 79
  • 107

2 Answers2

4

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_password\r"; interact};'
DougW
  • 28,776
  • 18
  • 79
  • 107
  • This works great! (Got an evil admin who doesn't allow pubkey auth) – Paul Voss Nov 22 '12 at 10:20
  • Glad to hear it. As @Mark O'Connor pointed out, just remember that this is pretty insecure. Make sure that fits with your use case requirements. – DougW Nov 26 '12 at 07:05
-2

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

Community
  • 1
  • 1
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Yeeeep, that uses a cert. Again, not saying that isn't the secure, correct way to do this most of the time. However, in my case I was explicitly interested in avoiding it. Who knows? Maybe we're dealing with a 3rd party server that doesn't accept keys, or that I can't install my cert on for some reason. Or just call it intellectual curiosity. Point is, question is explicit about not wanting the SSH key answer. – DougW Nov 01 '12 at 00:24