Sample code for 30+ languages & platforms
Visual Basic 6.0

SSH Authentication using an SSH Certificate

See more SSH Examples

Demonstrates how to authenticate using an SSH certificate.

Chilkat Visual Basic 6.0 Downloads

Visual Basic 6.0
Dim success As Long
success = 0

' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

Dim sbSshCert As New ChilkatStringBuilder
success = sbSshCert.LoadFile("qa_data/sshCert/user_ecdsa_key-cert.pub","utf-8")
If (success = 0) Then
    Debug.Print "Failed to load user_ecdsa_key-cert.pub"
    Exit Sub
End If

Dim sbPrivKey As New ChilkatStringBuilder
success = sbPrivKey.LoadFile("qa_data/sshKeys/user_ecdsa_key","utf-8")
If (success = 0) Then
    Debug.Print "Failed to load user_ecdsa_key"
    Exit Sub
End If

Dim key As New ChilkatSshKey
' Provide the password if the user_ecdsa_key is stored in an encrypted format.
key.Password = "secret"
success = key.FromOpenSshPrivateKey(sbPrivKey.GetAsString())
If (success = 0) Then
    Debug.Print key.LastErrorText
    Exit Sub
End If

' Indicate that the SSH certificate is to be used for authentication.
' The UseSshCertificate method was added in Chilkat v11.0.0
success = key.UseSshCertificate(sbSshCert.GetAsString())

Dim ssh As New ChilkatSsh

Dim hostname As String
hostname = "ssh.example.com"
Dim port As Long
port = 22
success = ssh.Connect(hostname,port)
If (success <> 1) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

success = ssh.AuthenticatePk("myLogin",key)
If (success <> 1) Then
    Debug.Print ssh.LastErrorText
    Exit Sub
End If

Debug.Print "Public-Key Authentication using an SSH Certificate was Successful!"