試圖通過用戶名和私鑰僅使用當前的ssh.net庫進行身份驗證。我無法從用戶那裏獲得密碼,所以這是不可能的。ssh.net僅通過私鑰進行身份驗證
這是我現在正在做的事情。
Renci.SshNet.ConnectionInfo conn = new ConnectionInfo(hostName, port, username, new AuthenticationMethod[]
{
new PasswordAuthenticationMethod(username, ""),
new PrivateKeyAuthenticationMethod(username, new PrivateKeyFile[] { new PrivateKeyFile(privateKeyLocation, "") }),
});
using (var sshClient = new SshClient(conn))
{
sshClient.Connect();
}
現在,如果i。從AuthenticationMethod[]
陣列I得到一個異常用於發現合適的認證方法除去PasswordAuthenticationMethod
。如果我試圖通過(主機名,端口,用戶名,密鑰文件2)這樣的
var keyFile = new PrivateKeyFile(privateKeyLocation);
var keyFile2 = new[] {keyFile};
再次,找不到合適的方法。
看來我必須使用ConnectionInfo
對象,因爲我上面列出,但似乎它評估PasswordAuthenticationMethod
和無法登陸(因爲我不提供密碼),從來沒有評估PrivateKeyAuthMethod
...這是案子?有沒有其他的方法來驗證只有用戶名或主機名和私鑰使用ssh.net lib?
啊,是的,這對我有效,謝謝! –