使用 Plink

问题描述

我正在尝试使用 Power Automate Desktop for PuTTY 进行自动化。我遇到了一个使用 cmd 使用 plink 运行命令的解决方案。 我使用了以下步骤:

  1. 我在系统变量中添加了 PuTTY

  2. 我使用了命令(在 cmd 中):

    plink -ssh hostname@ipaddress -pw password -no-antispoof -m C:\commands.txt
    
  3. 我编辑了command.txt

    ssh anotherIP -pw passwordForAnotherIP
    cd /tmp
    cat filename
    

当我在 cmd 中运行命令时,我无法在第一个服务器中输入需要访问的其他服务器的密码显示错误

坏端口'w'

服务器运行 bash 4.2。如何在 txt 文件命令中输入密码,以便命令行 plink 命令接受它?

解决方法

OpenSSH ssh 没有 -pw 开关。见Automatically enter SSH password with script

此外,您的 command.txt 无论如何都不会按照您的想法行事。它不会在 cd 中运行 catssh。它会在ssh之后运行它们。所以在 ipaddress 上。


相反,您可以使用 Plink's -proxycmd:

plink -ssh anotherIP -pw passwordForAnotherIP -no-antispoof -proxycmd "plink -ssh hostname@ipaddress -pw password -nc anotherIP:22" -m C:\commands.txt

commands.txt 只包含:

cd /tmp
cat filename