6

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.

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

This is what solved it for me, your issue could be different.

  1. In VScode, choose command: Remote-SSH: Open SSH Configuration File...
  2. Choose the location that is offered to you (or create a config file without extension to desired location), for example: C:\Users\[USER_NAME]\.ssh\config. Make sure you have appropriate permissions.
  3. Prepare you configuration file, for example
Host Custom_Name
  HostName example.server.com
  User your_user_name
  IdentityFile C:\Users\[USER_NAME]\Documents\MobaXterm\home\.ssh\id_rsa
  (or wherever you have the private key)
  1. Finally add a custom path to your configuration file. This is what I lacked for long time
{
// add custom configuration file path
"remote.SSH.configFile": "C:\\Users\\[USER_NAME]\\.ssh\\config",

// Other settings

// omit comma after *config"* if that is your last setting
}

Now it should ask for passphrase as opposed to password.

P.S. Here is a lot of useful information with the setup, especially with the keys that I have omitted for brevity.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.