admin管理员组文章数量:1344579
I'm trying to connect to a postgres db through an ssh tunnel.
I'm using the following code:
var key = @"-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACCXh/hzgihW+MyThoACSVPrcyxq2mR3X07BINeo0EAxRQAAAJgzheTNM4Xk
zQAAAAtzc2gtZWQyNTUxOQAAACCXh/hzgihW+MyThoACSVPrcyxq2mR3X07BINeo0EAxRQ
AAAECyv5JGjoNs6lPe8gdUjlSaOddVNJ4z3sF9ErOQpfcXwZeH+HOCKFb4zJOGgAJJU+tz
LGraZHdfTsEg16jQQDFFAAAAFW1yb3NhQE1ST1NBLUNMT1NFUi1QQw==
-----END OPENSSH PRIVATE KEY-----";
MemoryStream keyStream = new MemoryStream(Encoding.UTF8.GetBytes(key));
Renci.SshNet.ConnectionInfo connn = new Renci.SshNet.ConnectionInfo(
"141.147.35.80", "tml",
new AuthenticationMethod[]
{
new PrivateKeyAuthenticationMethod("tml", new PrivateKeyFile[] { new PrivateKeyFile(keyStream, ""), }),
});
SshClient client = new SshClient(connn);
client.Connect();
if (!client.IsConnected)
{
// Display error
Console.WriteLine("Client not connected!");
}
else
{
Console.WriteLine("Client connected!");
}
var port = new ForwardedPortLocal("10.5.10.43", 8080, "141.147.35.80", 22);
client.AddForwardedPort(port);
port.Start();
using (var conn = new NpgsqlConnection("Server=10.5.10.43;Database=trino;Port=8080;User Id=admin;Password=;"))
{
conn.Open();
}
port.Stop();
client.Disconnect();
But I'm always getting an error
Invalid private key
I've already used putty gen load key ->
Export open ssh key but I always got the same key format and the same error (Invalid private key).
How to get the right key to connect correctly through the tunnel?
本文标签: cSSHNET Authenticate via private key only throws invalid private keyStack Overflow
版权声明:本文标题:c# - SSH.NET Authenticate via private key only throws invalid private key - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743748412a2532191.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论