windowsbatch-filesshplinkpageant

How to list loaded SSH keys in Windows (pageant)


I'm trying to create simple Windows batch script that will manage connectivity to our client. That includes some tunnels using plink.exe and socks chain. Each hop requires ssh key authentication for which I'm using pageant.exe.

I have each piece scripted out as needed, except the pageant part, where I struggle. Facts encountered:

If I only start pageant.exe it will start pageant agent without any SSH key loaded and script will continue right away. Then I can run pageant.exe my_key.ppk to add the key into pageant and passphrase will be prompted, however script will continue meanwhile as well, so script will continue to plink part which will fail, because user will not provide passphrase till that time.

I've been looking into pageant docs and found some CLI switches like -l that supposedly should list loaded keys, that however does not seems to work on Windows version. Seems like windows version is only accepting arguments in form of .ppk files

I'd like to basically make some kind of "wait" function until user will provide passphrase. Is there any way how to either list loaded keys directly from pageant or any generic method asking Windows environment for SSH keys?


Solution

  • Pageant has -c switch, which you can use to pass a command to be executed after a private key is loaded:

    You can arrange for Pageant to start another program once it has initialised itself and loaded any keys specified on its command line. This program (perhaps a PuTTY, or a WinCVS making use of Plink, or whatever) will then be able to use the keys Pageant has loaded.

    You do this by specifying the -c option followed by the command, like this:

    C:\PuTTY\pageant.exe d:\main.ppk -c C:\PuTTY\putty.exe
    

    Though in general Pageant is a tool for an interactive use, not for scripting. For scripting, use -i switch of Plink to provide a private key for authentication.