Search code examples
windowsjmeterpageant

How can I use JMeter to load SSH keys in Pageant


I'm trying to load in a pre-generated SSH key which is located in %USERPROFILE%\\.ssh\id_rsa.ppk.

I have User Defined Variables set:

PAGEANT: "C:\Path_to_pageant\Pageant.exe"
   HOME: %USERPROFILE%
 ID_RSA: ${HOME}\.ssh\id_rsa_jmeter.ppk

The OS Process Sampler is configured as:

Command: ${PAGEANT}
  Value: "${ID_RSA}"

After it runs, it shows:

Executing: "C:\Path_to_pageant\Pageant.exe" "${HOME}\.ssh\id_rsa_jmeter.ppk"

and Pageant alerts that it couldn't find the key, no key is loaded.

If I change ID_RSA to %USERPROFILE%\.ssh\id_rsa_jmeter.ppk:

Executing: "C:\Path_to_pageant\Pageant.exe" "%USERPROFILE%\.ssh\id_rsa_jmeter.ppk"

and Pageant alerts that it couldn't find the key, no key is loaded.

If I copy and paste that command into a command prompt, it will add the key to Pageant. It appears that neither ${HOME} nor %USERPROFILE% is not being expanded.

Note: completely hard-coding the path will allow JMeter to import the key.


Solution

  • Replace your

    • %USERPROFILE% and
    • %HOME%

    variables with

    • ${__BeanShell(System.getenv("USERPROFILE"),)} and
    • ${__BeanShell(System.getenv("HOME"),)}

    accordingly.

    The approach above uses combination of System.getenv() Java SDK class method call and JMeter's __Beanshell function.

    To learn what else can be done using Functions see How to Use JMeter Functions post series.