Search code examples
visual-studio-codesshssh-keysvscode-remote

VSCode remote developement using ssh with passphrase protected ssh-key


I have a remote ssh server on which I want to do remote developement.
My public key is added to the authorized keys on the server and my private key is passphrase protected.

I added the remote host as described here using ssh user@host -i ~/.ssh/key

But whenever I try to open a new VSCode window on the remote host it fails and I see in the log that the connection timed out, which is expected because I don't get asked for my private-key passphrase.

I read this post on remote development using ssh and I searched on google but couldn't find any hints to what I could do to enable/enter ssh-key passphrase while connecting to remote host.

I know I can connect to the remote using a non-passphrase-protected key but I'm not asking for that, I want to know if it's possible to connect to a remote host from VSCode using a passphrase protected key.


Solution

  • If your key is not the default one, that means you need a ~/.ssh/config entry in which you specify your SSH connection parameters:

    Host myserver
      Hostname host
      User user
      IdentityFile ~/.ssh/key
    

    The Visual Studio Code Remote Development will automatically read the config file, and when you ask for opening an SSH session, you will see "myserver" entry: if you select it, the SSH session opened will use ~/.ssh/key, the right private key.

    Then, as long as your ssh-agent is enabled, and you have entered at least once your passphrase (through a manual ssh myserver), VSCode will use the same agent to get the passphrase when it will need it.