Using ssh tunnel with public and private keys (wodSSHTunnel)
Hello, i am no programmer and i am looking to create a simple tunnel from my PC to my server for simple port forward, and i have to use public and private keys, i have a project to generate the keys, the code i use is:
WODSSHKeyLib.Keys key = new WODSSHKeyLib.Keys();
key.Generate(WODSSHKeyLib.SSHKeyTypes.RSAkey, 1024);
key.PublicKeySave(WODSSHKeyLib.SSHKeyTypes.RSAkey, "public");
key.Save(WODSSHKeyLib.SSHKeyTypes.RSAkey, "private");
this creates 2 files, public and private in the bin directory, and then i have another project with this code:
WODSSHKeyLib.Keys key = new WODSSHKeyLib.Keys();
key.Load("private");
wodSSHTunnel1.Hostname = hostname;
wodSSHTunnel1.Login = "sshuser";
wodSSHTunnel1.Authentication = wodSSHTunnelCOMLib.AuthenticationsEnum.authPubkey;
wodSSHTunnel1.PrivateKey = key;
wodSSHTunnel1.Timeout = 120;
wodSSHTunnel1.Compression = 6;
wodSSHTunnel1.Connect();
on my server i have OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
and i logged in with my sshuser and created a file
vi ~/.ssh/authorized_keys2
and pasted the contents of "public" file created earlier.
but each time i try to use my second project i get
Invalid username or password reported by server, or bad private key.
I tried using putty with keys and it works, i used a tutorial i found online using puttygen.exe
Can you help me?
Using ssh tunnel with public and private keys
Talia,
hi. Are you saying that same key works with Putty? or different key? You can exchange keys if you wish, since Load method can load Putty's key (without password).
Your code looks ok to me, *EXCEPT* this line:
key.PublicKeySave(WODSSHKeyLib.SSHKeyTypes.RSAkey, "public");
I think you should use
key.PublicKeyOpenSSH
instead, since that extracts public key in OpenSSH format which is what you need.
Kreso
Using ssh tunnel with public and private keys
Hi, I forgot to ask, when I generate the key I saved the output of
string privatekey = key.ToXmlString(WODSSHKeyLib.SSHKeyTypes.RSAkey,true));
can I use this value in my other project like this:
WODSSHKeyLib.Keys key = new WODSSHKeyLib.Keys();
key.FromXmlString(@"the string from privatekey ");
wodSSHTunnel1.PrivateKey = key;
because I don't want to keep the private key file in the same folder, on my HDD.
Thanks
Using ssh tunnel with public and private keys
Hi.
Yes, exactly, you can do that.
Kreso
Using ssh tunnel with public and private keys
How can i use key.PublicKeyOpenSSH?
key.PublicKeyOpenSSH(WODSSHKeyLib.SSHKeyTypes.RSAkey, "public");
gives me
Error 20 Non-invocable member 'WODSSHKeyLib.IKeys.PublicKeyOpenSSH' cannot be used like a method.
or i have to define a new string a = key.PublicKeyOpenSSH;
but i get
Error 20 Indexed property 'WODSSHKeyLib.IKeys.PublicKeyOpenSSH' has non-optional arguments which must be provided
Thank you
Using ssh tunnel with public and private keys
I can't figure out how to use PublicKeyOpenSSH property...
I have the keys i generated with putty, can i use those?
How can i add them to key.FromXmlString()?
How can i transform the private keys that looks like this
PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: rsa-key-20140405
Public-Lines: 4
...
Private-Lines: 8
...
Private-MAC: ....
in a valid string so i can load with key.FromXmlString()?
Thanks, Alice
Using ssh tunnel with public and private keys
Hi.
PublicKeyOpenSSH is a property, so something like
Dim a a string
a = keys.PublicKeyOpenSSH (rsakey)
should work.
Kreso
Using ssh tunnel with public and private keys
Yes, you can use keys from putty. Load them using Load method, then export the way you need (usng ToXMLString) for later on.
Kreso