How to pass an ssh key passphrase via environment variable
<p>I run shell script with <code>ssh</code> command inside my application. Used private key is encrypted by passphrase and the problem is - I cannot interactively pass it when asked.Key is not added in <code>ssh-agent</code>. I cannot execute <code>ssh-add my_key</code> because the passphrase is suppose to be passed interactively. It's good for terminal communication, but not so good to use inside application. </p>

<p>The <code>man page</code> says: </p>

<blockquote>
  <p>DISPLAY and SSH_ASKPASS</p>
  
  <p>If ssh-add needs a passphrase, it will read the passphrase from the current terminal if it was run from a terminal.
               If ssh-add does not have a terminal associated with it but DISPLAY and SSH_ASKPASS are set, it will execute the
               program specified by SSH_ASKPASS and open an X11 window to read the passphrase.  This is particularly useful when
               calling ssh-add from a .xsession or related script.  (Note that on some machines it may be necessary to redirect
               the input from /dev/null to make this work.)</p>
</blockquote>

<p>When I execute <code>SSH_ASKPASS=file_with_passphrase ssh-add my_key</code> I still asked to type a passphrase, looks like env var is just ignored in that case. I tryed to execute <code>ssh -o BatchMode=yes</code> and server just rejected encoded key because no one was able to decoded it. </p>

<p>I definitely can decode ssh key manually before using it in <code>ssh-agent</code> but it looks like I'm about to get what I need from <code>SSH_ASKPASS</code> variable, but I don't know how to make it work. Happy to get community help.</p>