简体   繁体   English

如何使用JMeter在Pageant中加载SSH密钥

[英]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 . 我正在尝试加载位于%USERPROFILE%\\\\.ssh\\id_rsa.ppk中的预生成的SSH密钥。

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: OS Process Sampler配置为:

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. 并且Pageant会警告它找不到密钥,没有加载密钥。

If I change ID_RSA to %USERPROFILE%\\.ssh\\id_rsa_jmeter.ppk : 如果我将ID_RSA更改为%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. 并且Pageant会警告它找不到密钥,没有加载密钥。

If I copy and paste that command into a command prompt, it will add the key to Pageant. 如果我将该命令复制并粘贴到命令提示符下,它将把密钥添加到Pageant。 It appears that neither ${HOME} nor %USERPROFILE% is not being expanded. 看来${HOME}%USERPROFILE%都没有被扩展。

Note: completely hard-coding the path will allow JMeter to import the key. 注意:完全硬编码路径将允许JMeter导入密钥。

Replace your 更换您的

  • %USERPROFILE% and %USERPROFILE%
  • %HOME%

variables with 变量与

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

accordingly. 相应地。

The approach above uses combination of System.getenv() Java SDK class method call and JMeter's __Beanshell function. 上面的方法结合使用System.getenv() Java SDK类方法调用和JMeter的__Beanshell函数。

To learn what else can be done using Functions see How to Use JMeter Functions post series. 要了解使用函数可以完成的其他操作,请参阅如何使用JMeter函数帖子系列。

It is only %USERPROFILE% that is failing to expand ( ${HOME} expands to %USERPROFILE% , which subsequently fails to expand). 只有%USERPROFILE%无法扩展( ${HOME}扩展为%USERPROFILE% ,随后扩展失败)。

It is because the expansion is done by the command prompt shell, but not by the OS process sampler. 这是因为扩展是由命令提示符外壳完成的,而不是由OS进程采样器完成的。

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} 我认为获取%USERPROFILE%最佳方法是在启动时将其加载到属性中,然后在${HOME}使用该属性

Add -DUSERPROFILE=%USERPROFILE% to your JMeter startup command line, then use ${__P{USERPROFILE}} instead in the script. -DUSERPROFILE=%USERPROFILE%添加到JMeter启动命令行,然后在脚本中使用${__P{USERPROFILE}}

Another alternative is to change your command, so that it runs "cmd.exe /C \\path_to_pageant\\pageant.exe" . 另一种选择是更改命令,使其运行"cmd.exe /C \\path_to_pageant\\pageant.exe" This will call the command prompt to expand %USERPROFILE% before command prompt calls Pageant. 在命令提示符调用Pageant之前,这将调用命令提示符以展开%USERPROFILE%

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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