To authenticate to an SFTP server using client x509 certificate you have to:
- Generate a certificate for the specified SFTP user.
- Store the certificate with associated private key (.pfx file) at the client side.
- Store the certificate (.cer or .der file) at the server side and associate it with the specified SFTP user in your SFTP server.
Then authenticate to your SFTP server using Rebex Sftp
object like this:
// connect to a server
var sftp = new Rebex.Net.Sftp();
sftp.Connect(hostname, port);
// verify server's fingerprint
// ...
// load X509 certificate
Certificate x509 = Rebex.Security.Certificates.Certificate.LoadPfx(certPath, certPassword);
// wrap X509 certificate to SshPrivateKey
SshPrivateKey privateKey = new SshPrivateKey(x509);
// log in
sftp.Login(username, privateKey);