EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Hot to connect using a Public Key

Posted: 09/26/2007 00:15:29
by Rodney Lane (Standard support level)
Joined: 09/25/2007
Posts: 2

I am new to SSH connections etc so please excuse my ignorance...

I have loaded up the SimpleSFTPclient sample application and am trying to get it to use a public key file i was provided by my solaris administrator for connecting to the sftp server.

The public key is an ssh-keygen file (ssh-dss), and was wondering if anyone knew what I had to do to the SimplsSFTPDemo to get it to use the PublicKey file to connect, rather than a username and password.

According to my admin, i only need this public key, and dont need a password.

I modified the SimplsSFTPDemo code for the connect as follows:

Private Sub Connect()

Dim dlg As frmConnProps

If SftpClient.Active Then

System.Windows.Forms.MessageBox.Show(Me, "Already connected")

Exit Sub

End If

dlg = New frmConnProps

If (dlg.ShowDialog(Me) = Windows.Forms.DialogResult.OK) Then

SftpClient.Username = dlg.tbUsername.Text

SftpClient.Password = dlg.tbPassword.Text

SftpClient.Address = dlg.tbHost.Text

SftpClient.Port = 22


Dim key As New TElSSHKey

Dim result As Integer = key.LoadPublicKey("c:\pubkey.pub")


SftpClient.AuthenticationTypes = SBSSHConstants.Unit.SSH_AUTH_TYPE_PUBLICKEY



Catch ex As Exception

Log("SFTP connection failed: " + ex.Message, True)

Exit Sub

End Try

Log("SFTP connection established", False)

currentDir = "."


End If

End Sub

Stepping through the code in visual studio, When I load the public key from the file, it returns a 0 indicating that the public key was valid, but when it tries to open the connection, I get the following errors:

"Authentication Type 2 failed"
"SFTP Error 114"

Can anyone shed some light on what I am doing wrong?


Rodney lane.
Posted: 09/26/2007 01:49:57
by Eugene Mayevski (Team)

You can't authenticate using a public key - it's PUBLIC. You must have your own keypair. The private key is kept secure, and the public key (*your* public key, not the one that the admin has given you) is given to the admin. The admin will associate your public key with your user account on the server.

The admin could have given you a public key of the server for validation (i.e. when the client connects, it needs to check if the server key is the real one and not forged).

Sincerely yours
Eugene Mayevski
Posted: 09/26/2007 20:14:45
by Rodney Lane (Standard support level)
Joined: 09/25/2007
Posts: 2

thankyou - i just spoke with another admin today and he asked me to generate a key and send it to him. So hopefully that will solve the problem.

Thanks for your assistance.
Posted: 12/27/2007 12:06:49
by ankeet shah (Basic support level)
Joined: 12/27/2007
Posts: 3

Rodney, Eugene,

I am still confused about this - I have the same scenario as Rodney.
Admin from a different company gave us the Public Key and ofcourse he has his Private Key.
What do I need to do in that function call - use key.LoadPublicKey or key.LoadPrivateKey?

If key.LoadPrivateKey(dlg.edPrivateKey.Text, passwdDlg.Pass)

Also, dlg.edPrivateKey.Text is just the path\filename for the key, right or is it the actual key? Again, the confusion is which key should I use - other company's public or my private and my passphrase?
Excuse my ignorance about this concept - but I am brand new to this - about 4 hours old.

Thank You for your help!

Posted: 12/27/2007 12:22:01
by ankeet shah (Basic support level)
Joined: 12/27/2007
Posts: 3

Also, I want to use GnuPG to encrypt the files before I put them in the FTP Location and decrypt the files after I download them. Encryption/Decryption may not be a part of this discussion, I guess; but any help would be appreciated!
Posted: 12/27/2007 12:38:10
by Eugene Mayevski (Team)

PGP stuff is really a different topic.

As for the keys, the admin has given you their public key that you must use for validating the key that is received during SSH handshake. When the component calls OnKeyValidate event handler, you must compare the passed key to the key that you already have.

This is not authentication of you as a client, i.e. this is a different question from the one asked by the original poster.

Sincerely yours
Eugene Mayevski
Posted: 12/27/2007 12:39:13
by Eugene Mayevski (Team)

BTW please check the Knowledgebase, it will answer most of your questions.

Sincerely yours
Eugene Mayevski
Posted: 12/27/2007 12:44:27
by ankeet shah (Basic support level)
Joined: 12/27/2007
Posts: 3

Thank You Eugene. I will try going thru the KB again and try a different search! I appreciate the quick responses - unbelievable!




Topic viewed 3627 times

Number of guests: 1, registered members: 0, in total hidden: 0


Back to top

As of July 15, 2016 EldoS business operates as a division of /n software, inc. For more information, please read the announcement.

Got it!