SSH.NET Public 密钥验证
SSH.NET Public Key Authentication
我知道 有效,但我正在寻找 public 密钥验证。
我正在尝试使用 SSH.NET 和 public 密钥建立连接。
在 Git Bash 终端中,我可以使用我的 public 键连接和 运行 命令正常,但是当我尝试使用 [= 连接到同一主机时30=] 我得到一个例外。
这是我尝试连接的方式:
using (var client = new SshClient("host.name.com", port, "username"))
{
client.Connect(); // exception thrown here
}
我也试过这条路线:
var authMethod = new PrivateKeyAuthenticationMethod("username");
var info = new ConnectionInfo("host.name.com", port, "username", authMethod);
using (var client = new SshClient(info))
两者给出相同的异常:Permission denied (publickey).
好像我需要指定我的 public 钥匙在哪里,或者我需要把我的 public 钥匙放在某个地方,但我找不到任何文件告诉我放在哪里。
没有"private key authentication"。其实叫"public key authentication".
尽管您需要 私人和 public 密钥 才能使用 "public key authentication" 进行身份验证。它被称为 "public key authentication",因为客户端(在本例中为 SSH.NET)仅发送 public 密钥到服务器——因此服务器仅使用 public 密钥 对您进行身份验证。 私钥 仅在本地使用。
尽管文件格式通常被称为 私钥(如 PEM 或 .ppk)——与 public 密钥相反 (.pub) 格式 – 实际上包含整个密钥对(public 和私钥)。
所以您 link 提出的问题 – SSH.NET Authenticate via private key only (public key authentication) – 实际上是您想要的。它显示了如何使用 "public key authentication" 进行身份验证 – 使用 私钥 文件格式(public 和私钥 真的)。我已经编辑了该问题的标题以使其更清楚。
纠正一下,"In the Git Bash terminal I can connect and run commands fine using my public key" 是不正确的 – 这是不可能的。你也必须有私钥。
我知道
我正在尝试使用 SSH.NET 和 public 密钥建立连接。
在 Git Bash 终端中,我可以使用我的 public 键连接和 运行 命令正常,但是当我尝试使用 [= 连接到同一主机时30=] 我得到一个例外。
这是我尝试连接的方式:
using (var client = new SshClient("host.name.com", port, "username"))
{
client.Connect(); // exception thrown here
}
我也试过这条路线:
var authMethod = new PrivateKeyAuthenticationMethod("username");
var info = new ConnectionInfo("host.name.com", port, "username", authMethod);
using (var client = new SshClient(info))
两者给出相同的异常:Permission denied (publickey).
好像我需要指定我的 public 钥匙在哪里,或者我需要把我的 public 钥匙放在某个地方,但我找不到任何文件告诉我放在哪里。
没有"private key authentication"。其实叫"public key authentication".
尽管您需要 私人和 public 密钥 才能使用 "public key authentication" 进行身份验证。它被称为 "public key authentication",因为客户端(在本例中为 SSH.NET)仅发送 public 密钥到服务器——因此服务器仅使用 public 密钥 对您进行身份验证。 私钥 仅在本地使用。
尽管文件格式通常被称为 私钥(如 PEM 或 .ppk)——与 public 密钥相反 (.pub) 格式 – 实际上包含整个密钥对(public 和私钥)。
所以您 link 提出的问题 – SSH.NET Authenticate via private key only (public key authentication) – 实际上是您想要的。它显示了如何使用 "public key authentication" 进行身份验证 – 使用 私钥 文件格式(public 和私钥 真的)。我已经编辑了该问题的标题以使其更清楚。
纠正一下,"In the Git Bash terminal I can connect and run commands fine using my public key" 是不正确的 – 这是不可能的。你也必须有私钥。