【发布时间】:2021-12-05 13:38:31
【问题描述】:
我编写了一个 C# 控制台程序,通过 SSH 从 A(Windows 10,控制台 C# 应用程序)连接到 B(Linux 服务器)并从那里连接到 C(Linux 服务器),但我无法从 B 连接到 C(从A到B没问题)。 当我通过 Windows 终端从 A 连接到 B 并从 B 的终端连接到 C 时,它可以正常工作,因此我证明我的凭据很好。
-
我在 C# 中使用 Renci.SshNet
-
我使用
.Connect()、.Disconnect()和.Execute()扩展方法创建了一个类Server,然后创建了两个类实例Broker和Destination -
我的代码如下:
if (Broker.Connect()) { Broker.Execute("pwd"); if (Destination.Connect()) { Destination.Execute("pwd"); Destination.Disconnect(); } Broker.Disconnect(); } -
Ssh连接对象的创建类似于var broker = new SftpClient("Ip", Port, "User", "Pass") -
然后我在内部使用
broker.Connect()和broker.Disconnect()inRenci.Ssh.Netlib 给定方法 -
致
broker.Execute("cmd")我基本上是这样做的var output = host.Ssh.RunCommand(str); var res0 = output.ExitStatus; var res1 = output.Result; var res2 = output.Error; -
我的代码适用于第一部分,因为我设法获得了
Broker.Execute("pwd")的输出,但它没有连接到Destination.Connect(),返回消息A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond -
我的目标是使用 C# 中的自动化进程进行多跳:用户不得与任何控制台交互,并且我不能在 Linux 上修改或存储任何文件网站
知道问题出在哪里吗?
提前致谢,
【问题讨论】:
-
这很模糊。请edit您的问题包含您程序中的相关代码,并准确描述运行它时发生的情况。包括您收到的任何错误消息和堆栈跟踪。
-
请在您的主机上尝试
ssh userc@hostc -J userB@hostb。如果可行,您可以将主机添加到您的.ssh/config文件中 -
Destination.Connect可能会尝试直接从 hostA 连接到 HostC,我不相信它会为此使用 host-B -
@jeb 使用
ssh userc@hostc -J userB@hostb...我在哪里提供密码?对于Destination.Connect是的,这也是我的猜测……但我不知道/不知道如何解决它…… -
在命令行中使用
ssh,它会要求输入密码。然后避免密码使用密钥
标签: c# linux ssh ssh-tunnel