23

I'm using the vscode-sftp extension in my Visual Studio Code workflow to upload files to my remote server, whenever I hit save. I am trying to achieve password-less authentication as I used to do with Sublime Text's SFTP plugin. However, the catch is that for vscode-sftp, in the sftp.json file, I have to enter my Password as plain text for this to work:

{
    "host": "mysamplehost.com",
    "port": 22,
    "username": "username",
    "password": "password",
    "protocol": "sftp",
    "agent": null,
    "privateKeyPath": null,
    "passphrase": null,
    "passive": false,
    "interactiveAuth": false,
    "remotePath": "/",
    "uploadOnSave": true,
    ...
}

However, if I SSH into my server, I do not get asked for a password - since I have the SSH key in my MacBook. How do I configure vscode-sftp to use this authentication method?

I see the following comment in the documentation, however I don't know how to set this up:

  /**
   * string - Path to ssh-agent's UNIX socket for ssh-agent-based user authentication.
   * Windows users: set to 'pageant' for authenticating with Pageant or (actual) path to a cygwin "UNIX socket.
   */
  agent: null, 
  privateKeyPath: null, // absolute path to user private key
  passphrase: null,
  passive: false, // ftp passive mode
2
  • mini note; if you're using AWS EC2 you must use Public IPv4 DNS adres. Not Public IPv4 address.
    – hakki
    Oct 21, 2020 at 19:04
  • under macOS all I needed to do was add "agent": "$SSH_AUTH_SOCK" to my config.
    – Martin CR
    Sep 4, 2022 at 11:54

5 Answers 5

29

I figured it out after stumbling upon this. Here is how I did it. First, run:

$ echo $SSH_AUTH_SOCK

Enter the path to agent in your sftp.json file. Also enter the path to your private key (id_rsa file). The following config did the trick for me:

"agent": "/private/tmp/com.apple.launchd.nPw17MhOqq/Listeners",
"privateKeyPath": "/Users/amitsn/.ssh/id_rsa",
"passphrase": null,

Note that I do not have a passphrase, so I left it null. Do not forget to fill this one if you have one.

5
  • 1
    that agent path will change upon every reboot, the answer I found is over here https://apple.stackexchange.com/a/177419 Dec 5, 2017 at 19:45
  • 1
    @Amit Is this extension officially supported by Microsoft or VSCode? Does VSCode have a built-in sftp pluging/functionality?
    – Amir
    Jul 20, 2018 at 13:46
  • You can use the environment variable itself in the agent property. e.g. "agent": "${env:SSH_AUTH_SOCK}", Also, "privateKeyPath" is not a valid property, it should be "privateKey". If you look at the source code, you'll see that it's actually reading from a file. Jul 24, 2018 at 3:01
  • 1
    it should be "$SSH_AUTH_SOCK" and not "${env:SSH_AUTH_SOCK}"
    – Sarbbottam
    Sep 12, 2018 at 21:23
  • @DrewChapin your link doesn't display the source for sftp .. it displays only the ftp-simple source... both ways didn't work for me .. I always have to enter my passphrase .. so the agent doesn't work
    – MonTea
    Oct 20, 2018 at 18:32
20

For me, it was enough to just use the privateKeyPath option:

...
    "host": "my.site",
    "protocol": "sftp",
    "port": 22,
    "username": "username",
    "privateKeyPath": "/Users/username/.ssh/id_rsa",
...

Note: in order to login with the key, you need to install your key to the remote server first with ssh-copy-id username@my.site command.

2
  • 2
    This worked for me on a windows Machine too. Generated the key using putty and used the ppk like this with forward slashes: code
    – B. Clincy
    Nov 1, 2019 at 14:38
  • you're a life saver! Jul 27 at 19:45
5

You could do this.

"agent": "$SSH_AUTH_SOCK"
1
  • Yep - this was all I needed to do (VS Code v1.71.0 and SFTP v1.15.14, macOS Monterey v12.5.1)
    – Martin CR
    Sep 4, 2022 at 11:50
0

Enabling passphrase dialog:

"passphrase": true,

Described in Wiki. This works for Natizyskunk and liximomo.

I'm using a working fork of liximomo, since I get an annoying fake error message there.

0

Generate your ssh key specifying the ecdsa algorithm type: ssh-keygen -t ecdsa (Linux) PuTTY (Windows)

{
"name": "your_remote_server_name",
"host": "123.456.789.100",
"protocol": "sftp",
"port": 1234,
"username": "remote_user_name",
"privateKeyPath": "/home/local_user_name/.ssh/id_ecdsa",
"passphrase":true,
"remotePath": "/home/remote_user_name/folderxyz",
"uploadOnSave": true,
"useTempFile": false,
"openSsh": false
}

If you don't use a passphrase when generating your ssh key, remove ("passphrase":true,) from this code.

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.