【问题标题】:Executing command using Plink does not work, but does in PuTTY使用 Plink 执行命令不起作用,但在 PuTTY 中可以
【发布时间】:2017-10-05 17:33:57
【问题描述】:

我正在尝试创建一个 PowerShell 脚本以通过 SSH 连接到 Raspberry Pi 并执行一些命令。我正在使用 Plink 通过命令行通过 SSH 连接到 Pi。但是我必须通过 SSH 连接到在 lshell 中运行的 Pi 用户。我可以在零问题的情况下将 PuTTY 放入 Pi,但是在使用 Plink 时出现错误,提示我正在使用的命令被禁止。我正在尝试使用su,它在使用 PuTTY 而非 Plink 时有效。

我得到的错误如下:

plink : *** forbidden char/command over SSH: "su"
At line:1 char:1
+ plink -ssh pi@<IP> -pw <password> su
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (*** forbidden c... over SSH:         
"su":String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

This incident has been reported.

感谢您提供的任何帮助。

【问题讨论】:

    标签: powershell ssh raspberry-pi plink lshell


    【解决方案1】:

    使用plink ... command与使用PuTTY登录并输入command相比有两个不同:

    1. plink ... command 打开一个“exec”通道来运行命令。而 PuTTY 使用登录 shell 打开“shell”通道,并且只有 shell 运行命令。

    2. plink ... command 默认打开一个非交互式会话(无 TTY)。当 PuTTY 打开一个交互式会话时(使用 TTY)。


    在 PuTTY 中测试 Plink 行为:

    1. 输入命令Connection > SSH > Remote command
    2. 检查 Connection > SSH > TTY > 不要分配伪终端

    相反,要在 Plink 中测试 PuTTY 行为,请使用:

    echo command | plink ...
    

    也请查看 Plink -T/-t switches

    这在 2 中表现得像 PuTTY,但在 1 中却不是:

    plink -t ... command
    

    相反,这在 1 中表现为 PuTTY,但在 2 中则不然:

    echo command | plink -T ...
    

    用这些实验找出导致您的特定问题的原因。

    解决方案见Script via Plink in .bat behaves differently

    【讨论】:

      最近更新 更多