在 Plink 命令行上执行命令失败 "not found"

Executing command on Plink command line fails with "not found"

目标:通过 SSH 连接到 AntMiner,并发送 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" 失败了吗?

这包含在这些问题中:

  • Script via Plink in .bat behaves differently

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

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


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

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

echo poweroff| plink ...