Delphi ActiveX
Delphi ActiveX
Authenticate an SSH Tunnel with a Private Key
See more Socket/SSL/TLS Examples
Demonstrates Socket.SshAuthenticatePk, which authenticates an SSH tunnel session using a private key loaded into an SshKey object. Call SshOpenTunnel first.
The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.
Background. The SSH server must have the corresponding public key authorized for the account. If the private key is encrypted, set the SshKey.Password property before loading it.
Chilkat Delphi ActiveX Downloads
var
success: Integer;
socket: TChilkatSocket;
sshKey: TChilkatSshKey;
keyText: WideString;
begin
success := 0;
socket := TChilkatSocket.Create(Self);
success := socket.SshOpenTunnel('ssh.example.com',22);
if (success = 0) then
begin
Memo1.Lines.Add(socket.LastErrorText);
Exit;
end;
// Load the SSH private key. The file path is relative to the application's current working
// directory. If the key is encrypted, set the SshKey.Password property before calling
// FromOpenSshPrivateKey.
sshKey := TChilkatSshKey.Create(Self);
keyText := sshKey.LoadText('qa_data/id_ed25519');
if (sshKey.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(sshKey.LastErrorText);
Exit;
end;
success := sshKey.FromOpenSshPrivateKey(keyText);
if (success = 0) then
begin
Memo1.Lines.Add(sshKey.LastErrorText);
Exit;
end;
// Authenticate the SSH tunnel session using public-key authentication. The SSH server must have the
// corresponding public key authorized for the account.
success := socket.SshAuthenticatePk('sshUser',sshKey.ControlInterface);
if (success = 0) then
begin
Memo1.Lines.Add(socket.LastErrorText);
Exit;
end;
Memo1.Lines.Add('SSH public-key authentication succeeded.');