我知道私钥身份验证有效,但是我正在寻找公钥身份验证。
我正在尝试使用 SSH.NET 和公钥建立连接。
在 Git Bash 终端中,我可以使用公钥很好地连接并运行命令,但是当我尝试使用 SSH.NET 连接到同一主机时,出现异常。
这是我尝试连接的方式:
using (var client = new SshClient("host.name.com", port, "username"))
{
client.Connect(); // exception thrown here
}
Run Code Online (Sandbox Code Playgroud)
我也尝试过这条路线:
var authMethod = new PrivateKeyAuthenticationMethod("username");
var info = new ConnectionInfo("host.name.com", port, "username", authMethod);
using (var client = new SshClient(info))
Run Code Online (Sandbox Code Playgroud)
两者都给出相同的例外:Permission denied (publickey).
似乎我需要指定我的公钥在哪里,或者我需要将我的公钥放在某个位置,但我找不到任何文档告诉我将其放在哪里。