SSH.NET公钥身份验证 [英] SSH.NET Public Key Authentication

查看:223
本文介绍了SSH.NET公钥身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道私有密钥身份验证可以正常工作,但是我正在寻找公共密钥身份验证.

I know that private key authentication works, however I'm looking for public key authentication.

我正在尝试使用SSH.NET和公共密钥建立连接.

I'm trying to establish a connection using SSH.NET and a public key.

在Git Bash终端中,我可以使用公共密钥连接并运行命令,但是当我尝试使用SSH.NET连接到同一主机时,会出现异常.

In the Git Bash terminal I can connect and run commands fine using my public key, but when I try connecting to the same host using SSH.NET I get an exception.

这是我尝试连接的方式:

Here is my how I'm trying to connect:

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).

Both give the same exception: Permission denied (publickey).

似乎我需要指定我的公钥在哪里,或者我需要将公钥放在某个位置,但是找不到任何文档可以告诉我将其放在何处.

It seems as though I need to specify where my public key is, or I need to put my public key in a certain spot, but I can't find any documentation telling me where to put it.

推荐答案

没有私钥身份验证" .它实际上称为公钥身份验证" .

尽管您需要公钥和私钥,才能使用公钥身份验证" 进行身份验证.之所以称为公钥身份验证" ,是因为客户端(在本例中为SSH.NET)仅向服务器发送 public 密钥-因此服务器使用<仅限em>公钥. 私钥仅在本地使用.

Though you need both private and public key to authenticate using "public key authentication". It's called "public key authentication", because a client (SSH.NET in this case) sends only the public key to the server – So the server authenticates you using the public key only. The private key is used locally only.

尽管通常称为私钥的文件格式(例如PEM或.ppk)(与公钥(.pub)格式相反)实际上包含整个密钥对(公钥和私钥).

Though file formats that are commonly referred to as a private key (like PEM or .ppk) – as opposite to public key (.pub) formats – actually contain whole key pair (both public and private key).

因此,您链接到的问题– SSH.NET仅通过私钥进行身份验证(公钥身份验证) –实际上做你想要的.它显示了如何使用公钥身份验证" 进行身份验证–使用私钥文件格式(实际上是公钥和私钥).我已经编辑了该问题的标题,以使其更加清楚.

So the question that you link to – SSH.NET Authenticate via private key only (public key authentication) – actually does what you want. It shows how to authenticate using "public key authentication" – using private key file format (both public and private key really). I've edited the title of that question to make this more clear.

为了纠正你,在Git Bash终端中我可以使用我的公钥很好地连接并运行命令"是不正确的. –这是不可能的.您也必须有一个私钥.

And to correct you, it's not true that "In the Git Bash terminal I can connect and run commands fine using my public key" – That's not possible. You must have a private key too.

这篇关于SSH.NET公钥身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆