Problems Setting up SFTP Storage Type - Invalid Private Key


Hi there,

First time user trying to get an SFTP storage type working. When I enter my credentials for the “Backup destination” and hit “Test connection” I get the following error: "Failed to connect: Invalid private key file. " I also get the following two errors in the “Log data from the server”:

Request for http://localhost:8200/api/v1/remoteoperation/test gave error
Renci.SshNet.Common.SshException: Invalid private key file.
   at Renci.SshNet.PrivateKeyFile.Open(Stream privateKey, String passPhrase)
   at Renci.SshNet.PrivateKeyFile..ctor(String fileName, String passPhrase)
   at Duplicati.Library.Backend.SSHv2.ValidateKeyFile(String filename, String password)
   at Duplicati.Library.Backend.SSHv2.CreateConnection()
   at Duplicati.Library.Backend.SSHv2.List()
   at Duplicati.Server.WebServer.RESTMethods.RemoteOperation.TestConnection(String url, RequestInfo info)
   at Duplicati.Server.WebServer.RESTHandler.DoProcess(RequestInfo info, String method, String module, String key)


Reporting error gave error
System.ObjectDisposedException: Cannot write to a closed TextWriter.
   at System.IO.__Error.WriterClosed()
   at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
   at Duplicati.Server.WebServer.RESTHandler.DoProcess(RequestInfo info, String method, String module, String key)

I do use keys to authenticate and under advanced options I did add an “ssh-keyfile”. I used the path to the keyfile that I use successfully with WinSCP to make a SFTP connection. I also have my keyfile encrypted and I did enter the password to decrypt it in the password field. I also tried the “ssh-key” option and just pasted the contents of the keyfile in along with “sshkey://” at the beginning as instructed.

I think the problem may be that the keyfile was generated with Putty and not directly with OpenSSH? I am not really sure how to correct this though.

Any tips are very much appreciated, thank you!


It does look like it’s an error with reading the format. Did Putty make a .ppk file as private key?

And does your file look correct when you open it in a text editor?

It should looke something like this:


but .ppk’s usually look like this:

PuTTY-User-Key-File-2: ssh-rsa
Encryption: none
Comment: imported-openssh-key
Public-Lines: 6
Private-Lines: 14

It should also be noted that Renci.SshNet does not support anything but RSA and DSA (Non-RSA SSH key rejected with poor error message · Issue #2950 · duplicati/duplicati · GitHub)


Thank you Pectojin! You set me on the right track to fixing this. I was indeed using a .ppk file generated with Putty. How I fixed the issue was to open the ppk file with PuttyGen using the “load” button, then I selected Conversions > Export OpenSSH Key and saved that file. Entering the path to that file worked!


I don’t know if it’s still the case, but Putty used to only support .ppk files, so I figured it must be :slight_smile:


Awesome, that also solved my problem… I didn’t know that puttygen could convert ppk’s like that so thank you very much for posting your solution most people just say it’s solved and move on