【问题标题】:Executing command on Plink command line fails with "not found"在 Plink 命令行上执行命令失败并显示“未找到”
【发布时间】:2018-07-04 20:25:22
【问题描述】:

目标:通过SSH连接蚂蚁矿机,发送poweroff命令。

命令:plink.exe -v -t -ssh antminer -l root -pw xxx poweroff

Connecting to 10.0.1.11 port 22  
We claim version: SSH-2.0-PuTTY_Release_0.70  
Server version: SSH-2.0-dropbear_2012.55  
Using SSH protocol version 2  
Using Diffie-Hellman with standard group "group14"  
Doing Diffie-Hellman key exchange with hash SHA-1  
Host key fingerprint is:  
ssh-rsa 1039 xxx  
Initialised AES-256 SDCTR client->server encryption  
Initialised HMAC-SHA1 client->server MAC algorithm  
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm  
Using username "root".  
Sent password  
Access granted  
Opening session as main channel  
Opened main channel  
Allocated pty (ospeed 38400bps, ispeed 38400bps)  
Started a shell/command  
sh: poweroff: not found  
Server sent command exit status 127  
Disconnected: All channels closed

所以连接工作正常,是命令的发送出错了。 以下是应该发生的情况:(这次手动发送命令)

命令:plink.exe -v -t -ssh antminer -l root -pw xxx

Connecting to 10.0.1.11 port 22
We claim version: SSH-2.0-PuTTY_Release_0.70
Server version: SSH-2.0-dropbear_2012.55
Using SSH protocol version 2
Using Diffie-Hellman with standard group "group14"
Doing Diffie-Hellman key exchange with hash SHA-1
Host key fingerprint is:
ssh-rsa 1039 xxx
Initialised AES-256 SDCTR client->server encryption
Initialised HMAC-SHA1 client->server MAC algorithm
Initialised AES-256 SDCTR server->client encryption
Initialised HMAC-SHA1 server->client MAC algorithm
Using username "root".
Sent password
Access granted
Opening session as main channel
Opened main channel
Allocated pty (ospeed 38400bps, ispeed 38400bps)
Started a shell/command
root@antMiner:~# poweroff

Broadcast message from root@antMiner (pts/0) (Thu Jan 25 19:23:19 2018):

The system is going down for system halt NOW!
root@antMiner:~# Server unexpectedly closed network connection
FATAL ERROR: Server unexpectedly closed network connection

有人知道为什么通过 plink 发送命令“poweroff”会失败吗?

【问题讨论】:

    标签: batch-file ssh putty plink


    【解决方案1】:

    这些问题涵盖了这一点:


    所以一个简单的解决方案是,您可以在正常会话中尝试which poweroff,以查看poweroff 所在的位置(可以是/sbin/poweroff)。然后在 plink 命令行中使用完整路径。

    虽然正确的解决方案是修复您的启动脚本。请参阅上面的链接。


    由于即使使用-t 开关,您的命令行也无法工作,因此您的 SSH 服务器必须以不同的方式在“exec”通道中执行命令(在命令行上提供命令或使用 -m 开关时使用)比在“shell”通道中。这很不寻常。

    您可以通过输入重定向强制plink 使用“shell”通道(如在交互式会话中):

    echo poweroff| plink ...
    

    【讨论】:

    • 使用which poweroff后,确实在/sbin/poweroff。
    猜你喜欢
    • 1970-01-01
    • 2015-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多