Entering Private Key Passphrase with Putty Command Line PSFTP.exe

I'm using psftp.exe to automate a file download but need to connect with a private key as explained below. I am able to connect, however, the private key requires a Passphrase.

This procedure works but I have to enter the Passphrase from the keyboard, which defeats the process of running from command line. I would like to know if anyone can tell me how to send the Passphrase in the command line.

Using Putty's PSFTP.exe With A Private Key

Command Line:

    c:\putty\psftp.exe [email protected] -i putty_id_rsa_1024.ppk -b c:\putty\myscript.scr

Command Line Notes:  Replace username with your login name and modify the "putty_id_rsa_1024.ppk" key name to match your key. In order to use a key, you will need to use puttygen.exe to generate, import, and or export your keys. PuTTY requires a putty key file to make a private key connection. 

myscript.scr file contents:

cd /
put File1.txt

put File2.txt

put File3.txt

close

Script Notes: Each command is a standard Unix navigation command.  

As mentioned above, can anyone tell me how to send the private key Passphrase in the command line?


Solution 1:

Why not just remove the passphrase from the key? There is no value in having a passphrase on your key if you are just going to save the password somewhere in a config file or script.

Just load up your ppk file with puttygen, remove the password and save.

You can certainly make a copy of your ppk just and strip the phrase just from that copy, and then protect that copy with filesystem ACLs to minimize the risk.

Solution 2:

You can load the key into pageant when you log in and provide the passphrase just once. As long as pageant is running then all psftp/PuTTy/plink connections will use the key stored in it.