简体   繁体   中英

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.

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.

It is only %USERPROFILE% that is failing to expand ( ${HOME} expands to %USERPROFILE% , which subsequently fails to expand).

It is because the expansion is done by the command prompt shell, but not by the OS process sampler.

Best way I can think to get the %USERPROFILE% would be to load it into a property at startup, then use the property in ${HOME}

Add -DUSERPROFILE=%USERPROFILE% to your JMeter startup command line, then use ${__P{USERPROFILE}} instead in the script.

Another alternative is to change your command, so that it runs "cmd.exe /C \\path_to_pageant\\pageant.exe" . This will call the command prompt to expand %USERPROFILE% before command prompt calls Pageant.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM