I am using Sublime Text with the SFTP plugin. For my project I have set up a sftp-config.json file specifying the details necessary for the FTP connection. As long as I use a normal user/password login everything works fine and I can establish a connection.
However, I then tried to use an ssh key instead. My ssh key file is C:/Users/<username>/.ssh/id_rsa
. When I manually run sftp on the power shell, a connection is successfully established.
PS C:\> sftp -i C:/Users/<username>/.ssh/id_rsa <username>@<host>
Connected to <username>@<host>.
Of course, username
and host
are replaced with my actual credentials.
Now, when trying to do the same using Sublime Text with the SFTP plugin, it does not work. Instead, when connecting I am prompted to enter my password like when not using an ssh key. I also made sure that it's not the password of the key it is asking (the key currently does not have a password) and just hitting enter without entering a password does not lead to success. It seems to me like the plugin simply ignored the fact that I have supplied an SSH key: If I enter my password for the FTP server, it does connect successfully, but of course that's not what I want.
I was thinking that I must have made a mistake in the configuration file, but I can not figure out what it should be. I also read the documentation online and it does not mention any additional steps that should be necessary. Here is my configuration file (with certain replacements of course):
{
"type": "sftp",
"save_before_upload": true,
"upload_on_save": false,
"sync_down_on_open": false,
"sync_skip_deletes": false,
"sync_same_age": true,
"confirm_downloads": false,
"confirm_sync": true,
"confirm_overwrite_newer": false,
"host": "<host>",
"user": "<username>",
"remote_path": "<remotepath>",
"ignore_regexes": [
"\\.sublime-(project|workspace)", "sftp-config(-alt\\d?)?\\.json",
"sftp-settings\\.json", "/venv/", "\\.svn/", "\\.hg/", "\\.git/",
"\\.bzr", "_darcs", "CVS", "\\.DS_Store", "Thumbs\\.db", "desktop\\.ini"
],
"connect_timeout": 30,
"ssh_key_file": "C:/Users/<username>/.ssh/id_rsa"
}
As an alternative approach I also tried specifying "sftp_flags": ["-i", "C:/Users/<username>/.ssh/id_rsa"]
instead of using the ssh_key_file
setting, but to no avail.
Has anyone got this to work and can give me a tip on what I am doing wrong?
I was able to identify the problem: The SFTP plugin for Sublime Text uses psftp (Putty sftp client) on Windows. Psftp doesn't work with OpenSSH keys because it uses a different format for the key file. Therefore, I had to convert my OpenSSH key to a PPK key using Puttygen (the Putty key generator). Using this tool I was able to load my key and convert it to a PPK file (choose Conversions > Import key
from the menu and then then select Save private key
). This key would then work with the Sublime Text plugin.