Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to write a script that will deploy a build created on my desktop machine (windows/cygwin) to a machine in my test environment (linux).

I would like to use scp to copy the build to the target machine. The only account on the target machine is root, and I cannot create a special user for this task. The root user is unable to log in using an ssh key (I suspect that this is configured on the ssh server, but I do not know which configuration options control this). At any rate, I cannot change the configuration of the ssh server.

My desktop machine uses Cygwin, and I have ssh installed. What I need is the command-line-fu that will allow me to put the password on the command line.

I am aware of the dangers of having a plaintext password in a shell script, but that is not a concern here.

share|improve this question
3  
1  
Are you a system administrator on the target server ? –  Iain May 27 at 13:55
    
I have the root password for the target server, however, I'm only allowed to use it to deploy test builds. I am not permitted to change the server's configuration. –  spierepf May 27 at 14:41

2 Answers 2

up vote 3 down vote accepted

IMO, your best bet is to use some sort of expect script. My usual tricks for throwing a password at a command like this aren't working in my Cygwin installation.

share|improve this answer
2  
That's by design in ssh. It's incredibly difficult to feed passwords in on the command line to ssh and scp, simply because it's dangerous and unnecessary when you have public-private key auth (even passwordless) as an alternative option. –  Sobrique May 27 at 14:04
    
Thanks, I'd never used expect before. –  spierepf May 27 at 14:48
    
It's useful. I do recommend trying to get the server to accept an SSH key long-term, but if that's not possible for whatever reason, expect should at least let you hack dirtily around it. –  John May 27 at 15:03

I recommend using an ssh key for this purpose. If you can log in as root, you can also change the configuration of the ssh server.

As the next option, you can set the SSH_ASKPASS environment variable to point to a script that you write, that script just has to output the password on stdout.

There is a few prerequisites for SSH_ASKPASS to work:

  • The ssh command must not have access to a tty.
  • The ssh command must think it has access to an X server. It should be sufficient to have the necessary environment variables set, even if the X server they point to does not exist.
  • The server must support password authentication.

One problem that I ran into when trying to do the above with an embedded system was an ssh server which did not support password authentication. Instead it used keyboard-interactive, but configured in a way that made it look like password authentication.

As a last resort if none of the above works you need to wrap the ssh command in a script, which fakes a tty and feed the password through that. I used expect to achieve that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.