无法通过 Plink 的 SSH 会话在 Windows 服务器上执行命令
我正在尝试使用 Plink 在远程服务器上运行命令。两者,本地和本地远程机器是Windows。虽然我可以使用 Plink 连接到远程计算机,但我无法使用“-m 文件”选项。我尝试了以下三种方法,但没有成功:
尝试 1:
plink.exe -ssh -pw mypwd john.doe@server -m file.txt
输出:
Could not chdir to home directory /home/john.doe: No such file or directory
dir: not found
'file.txt' 仅包含一个命令,即 dir
尝试 2:
plink.exe -ssh -pw mypwd john.doe@server dir
输出:
Could not chdir to home directory /home/john.doe: No such file or directory
dir: not found
尝试 3:
plink.exe -ssh -pw mypwd john.doe@server < file.txt
在这种情况下,我得到以下输出:
Using username "john.doe".
****USAGE WARNING****
This is a private computer system. This computer system, including all
..... including personal information, placed or sent over this system
may be monitored.
Use of this computer system, authorized or unauthorized, constitutes consent
... constitutes consent to monitoring for these purposes.
dirCould not chdir to home directory /home/john.doe: No such file or directory
Microsoft Windows [Version x.x.xxx]
(C) Copyright 1985-2003 Microsoft Corp.
C:\Program Files\OpenSSH>
在我得到上面的提示,它挂起。在这方面有什么帮助吗?
I am trying to use Plink for running commands on remote server. Both, local & remote machine are Windows. Though I am able to connect to the remote machine using Plink, i am not able to use the '-m file' option. I tried the following three ways but to no avail:
Try 1:
plink.exe -ssh -pw mypwd john.doe@server -m file.txt
Output:
Could not chdir to home directory /home/john.doe: No such file or directory
dir: not found
'file.txt' only contains one command i.e., dir
Try 2:
plink.exe -ssh -pw mypwd john.doe@server dir
Output:
Could not chdir to home directory /home/john.doe: No such file or directory
dir: not found
Try 3:
plink.exe -ssh -pw mypwd john.doe@server < file.txt
In this case, I get the following output:
Using username "john.doe".
****USAGE WARNING****
This is a private computer system. This computer system, including all
..... including personal information, placed or sent over this system
may be monitored.
Use of this computer system, authorized or unauthorized, constitutes consent
... constitutes consent to monitoring for these purposes.
dirCould not chdir to home directory /home/john.doe: No such file or directory
Microsoft Windows [Version x.x.xxx]
(C) Copyright 1985-2003 Microsoft Corp.
C:\Program Files\OpenSSH>
After I get the above prompt, it hangs. Any help in this regard?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来
plink -m
工作正常:file.txt 中的命令正在发送到服务器。但是,您的 SSH 服务器正在运行一个 shell(可能是
bash
,因为 OpenSSH for Windows 使用 Cygwin),该 shell 无法理解您正在使用的命令,例如move
和dir
。因为bash
实现了这些命令的自己版本(分别为mv
和ls
)。正如您所发现的,您需要在 Windows 目录外运行cmd.exe /C
以便 SSH 服务器正确解释命令的含义。另一种选择是直接使用命令的bash
版本。It seems like
plink -m
is working fine: the commands from file.txt are being sent to the server.However, your SSH server is running a shell (probably
bash
because OpenSSH for Windows uses Cygwin) that does not understand the commands you are using, likemove
anddir
. Becausebash
implements its own versions of those commands (mv
andls
, respectively). As you discovered, you need to runcmd.exe /C
out of the Windows directory for your SSH server to correctly interpret the meaning of your commands. The other option is to use thebash
versions of the commands directly.这现在正在发挥作用。
plink -ssh -pw xxx john.doe@server cmd.exe /c move c://sample//jd//file.txt c://test//
This is working now.
plink -ssh -pw xxx john.doe@server cmd.exe /c move c://sample//jd//file.txt c://test//
您正在 Windows 服务器上通过 Cygwin 使用 OpenSSH。
Cygwin 在 Windows 上模拟 Unix 环境。
所以你必须使用Unix,而不是Windows命令(例如
mv
而不是move
或rename
)并且你需要使用类Unix路径,而不是Windows 路径(特别是正斜杠)。
此外,您的服务器似乎配置错误。
这可能是帐户配置不正确。该错误与您正在执行的命令无关。
You are using OpenSSH over Cygwin on your Windows server.
The Cygwin emulates Unix environment on Windows.
So you have to use Unix, not Windows commands (e.g.
mv
notmove
orrename
)And you need to use Unix-like paths, not Windows paths (forward slashes in particular).
Moreover, your server seems wrongly configured.
This is likely an incorrectly configured account. The error is not related to the commands you are executing.