SSHClient supports public key authentication. Depending on the requirements of the SSH server, it can be used instead of or alongside password authentication.
To use public key authentication, you need to load a private key file. The component supports the PPK format as generated by the PuTTYgen utility (an RSA and DSA key generation utility). This format was chosen for these reasons:
You can get the puttygen utility from the PuTTY website (direct link: http://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe).
The PuTTYPrivateKeyFile class implements the PPK file format. Load your private key file into the class by using the Read() method or the constructor. The class takes the data from a Stream object that you supply or from an AbstractFile and a passphrase (if used) to decrypt the private key.
The passphrase can be a string or a byte array (generated by encoding the passphrase string into ASCII bytes).
The Read method will throw an SSHIncorrectPasswordException if the passphrase for the private key is incorrect. It will throw an SSHPublicKeyAuthenticationDataException if the private key file is malformed, uses unsupported algorithms, or if the message authenticity code check for the private key fails when an unencrypted private key file is used.
Once you've successfully loaded your private key file into a PuTTYPrivateKeyFile object, you supply that object to the Authenticate method. The method has a flavor that takes a username string and a ISSHPublicKeyAuthenticationData object. PuTTYPrivateKeyFile implements this interface.
Authenticate() will throw a SSHAuthenticationFailedException if the public key is rejected by the server. Authenticate() will throw a SSHAuthenticationPartialSuccessException if the public key is accepted by the server but more authentications are required. If that happens, you can then call Authenticate again with your username and password to attempt the 'password' authentication method.
The PPK file format has multiple versions: 1, 2 and 3. All versions are written as .ppk files. Version 1 files are very old and no longer used in the field. Version 2 files are the most common. Starting with PuTTY version 0.75, version 3 of the file format was introduced. The PuTTYPrivateKeyFile class only supports version 2 files. An exception will be thrown if a version 3 files is loaded by the class.
Using the puttygen utility, it is possible to convert a version 3 PPK file to a version 2 PPK file.