Method SFTPClient():setKeyFile() Foundation

Sets a SSH key file for authentication.

Syntax
:setKeyFile( <cKeyFile>, [<cPassPhrase>], [<cPublicKeyFile>] ) --> self
Parameters
<cKeyFile>
The path to the key file.
<cPassPhrase>
An optional passphrase for decrypting the private key in the key file if it is password-protected.
<cPublicKeyFile>
An optional path to the public key file if it cannot be derived from the private key in the key file.
Return

This method returns self.

Description

Configures SSH key-based authentication by specifying the key file and optionally its passphrase and public key. This method enables public/private key authentication as an alternative to password-based login.

This method must be called before connecting to the SFTP server if public/private authentication is desired.

Using OpenSSH the key file can be generated from the command shell using the ssh-keygen.exe tool. In this example the public key can be derived from the private key so that the parameter <cPublicKeyFile> can be omitted:

ssh-keygen.exe -t rsa -b 4096 -f id_rsa 

The resulting file id_rsa contains the private key and can be passed with the parameter <cKeyFile>. The content of the resulting public key file id_rsa.pub needs to be deployed on the server. This is typically the file authorized_keys which is located on a windows based server in %HOMEPATH%\.ssh and ~/.ssh on a linux based server.

If the private key in the key file is password-protected, the passphrase must be provided with the parameter <cPassPhrase>.

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.