Hello,
I have previously been using Securebridge sFTP in an app to upload files to a server. The target server has been moved and admin prefers all access be done via key pairs. My first thought was to setup a separate linux host for sftp that supports key pair but also password authentication for this particular purpose, but thought I would first try seeing if it is possible to do with securebridge. I have the keys used by Putty to connect and used puttykeygen to get the ssh rsa key .
What is the correct way to connect in this instance?
Regards,
Lou
SFTP connect with RSA public key
Re: SFTP connect with RSA public key
SecureBridge supports simultaneous authentication by public key and password. For this, you should set the TScSSHClient.Authentication property to atPublicKey, and the properties ScSSHClient.PrivateKeyName and ScSSHClient.Password - to private key name and server password respectively.
The fact is that PuTTY saves keys in its own format. You should export your keys in the OpenSSH or SSH2 format. For that you should load your private key in PuTTY Key Generator, and export it to any available format using the Conversions menu. After that you should import this key in TScStorage using the TScKey.ImportFrom method, and set the imported key name in the TScSSHClient.PrivateKeyName property. After that connect to the SSH server.
You can use the following code:
The fact is that PuTTY saves keys in its own format. You should export your keys in the OpenSSH or SSH2 format. For that you should load your private key in PuTTY Key Generator, and export it to any available format using the Conversions menu. After that you should import this key in TScStorage using the TScKey.ImportFrom method, and set the imported key name in the TScSSHClient.PrivateKeyName property. After that connect to the SSH server.
You can use the following code:
Code: Select all
procedure Connect;
var
Key: TScKey;
begin
Key := TScKey.Create(ScFileStorage.Keys);
Key.KeyName := 'key1';
Key.ImportFrom(Filename);
ScSSHClient.Authentication := atPublicKey;
ScSSHClient.Password := 'password';
ScSSHClient.KeyStorage := ScFileStorage;
ScSSHClient.PrivateKeyName := 'key1';
ScSSHClient.Connect;
end;