Equivalent code to plink command
Hi I am trying to replicate this plink command:
plink.exe -L 5900:localhost:5900 -i key.ppk user@remotehost
with SSH.NET like this:
var keyfile = new PrivateKeyFile(@"key.ppk");
var method = new PrivateKeyAuthenticationMethod("user", keyfile);
var connectinfo = new ConnectionInfo(remotehost, "user", method);
using (var client = new SshClient(connectinfo))
{
client.Connect();
var port = new ForwardedPortLocal("localhost", 5900, "remotehost", 5900);
client.AddForwardedPort(port);
port.Exception += delegate(object sender, ExceptionEventArgs e) {
Console.WriteLine(e.Exception.ToString()); };
port.Start();
...
}
but it does not work and it does not throw any exception with the latest beta release (from Nuget).
Any ideas? Am I missing something?
Thanks
@aberbegall : I assume you want to tunnel VNC port from the remote box to your workstation via SSH.
Quick and dirty example:
ConnectionInfo connection = new ConnectionInfo("192.168.1.113", 22, "kasbst",
new PasswordAuthenticationMethod("kasbst", "password"));
using (SshClient ubuntubox = new SshClient(connection))
{
ubuntubox.Connect();
var port = new ForwardedPortLocal("127.0.0.1", 5900, "192.168.1.113", 5901);
ubuntubox.AddForwardedPort(port);
port.Exception += delegate (object sender, ExceptionEventArgs e) {
Console.WriteLine(e.Exception.ToString());
};
port.Start();
if (ubuntubox.IsConnected && port.IsStarted)
{
Console.WriteLine("Connected and tunnel established! Use localhost::5900 " +
"in your vncviewer to connect");
}
Console.WriteLine("Press any key to close the tunnel!");
// Keep the tunnel opened for demonstration
Console.ReadKey();
port.Stop();
ubuntubox.RemoveForwardedPort(port);
ubuntubox.Disconnect();
}


Let me know if you need more help.
@kasbst sorry for my late feedback Please notice I am using a private Key file and PrivateKeyAuthenticationMethod and you used a Password in your example.
If I run
netstat -anob
I can see that the connection with the remote host was ESTABLISHED on port 22 and the locally is LISTENING on the specified port as expected.
No exception is thrown but it simply does not work :(
AFAIR ppk-Files (Putty private key) wont work as private keys.
src/Renci.SshNet/PrivateKeyFile.cs
/// Supports RSA and DSA private key in both
Edit: oops! forgot the not
Ppk files are formatted differently. On the error of permission denied is the key protected via a passphrase?
On Aug 10, 2017, at 9:24 AM, Stefan Rinkes [email protected] wrote:
AFAIR ppk-Files (Putty private key) work as private keys.
src/Renci.SshNet/PrivateKeyFile.cs /// Supports RSA and DSA private key in both OpenSSH and ssh.com format.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sshnet/SSH.NET/issues/201#issuecomment-321549778, or mute the thread https://github.com/notifications/unsubscribe-auth/AAf0HqDdo7TxfuoJO6nrzXeC44bnHxOOks5sWwSUgaJpZM4M3xf-.
@darinkes I used a ssh.com key format, so it's not plink format. But this does not solve the problem. @darkoperator this is not a problem anymore, it's solved... I don't get any error/exception it just does not work.
Does the ssh.net expect to somehow acceptance of the server host key? I wonder whether I am missing the client acceptance of the server fingerprint, similar like pink when prompts to accept a key fingerprint for a particular host the first time it runs and stores it on its registry cache. Or perhaps I need to add the host IP to the trusted hosts, I am just thinking out loud since I have no clue where the issue is.