Cannot access EC2 instance with VSCode

Viewed 1854

I have created an Ubuntu (18.04) EC2 instance. Using bash ssh I can log in without any issue. But when I try the same VSCode I'm running into issues.

My config file in .ssh/ has an entry like:

Host MyBox
  HostName IPADDRESS
  IdentityFile C:\Users\myname\mykey.pem
  User ubuntu

I select this option to connect in VSCode but I get a dialog saying Could not establish connection to "MyBox". Connecting was canceled.

The output window says:

[14:03:27.443] > The authenticity of host 'XXX (XXX)' can't be established.
> ECDSA key fingerprint is SHA256:LALALALALA
> Are you sure you want to continue connecting (yes/no)?
[14:03:27.444] Detected fingerprint confirmation message
[14:03:27.444] Showing fingerprint confirmation dialog
[14:03:29.815] Fingerprint dialog canceled
[14:03:29.816] "install" terminal command canceled
[14:03:29.817] Resolver error: Connecting was canceled
[14:03:29.820] TELEMETRY: {"eventName":"resolver","properties":{"outcome":"failure","reason":"Canceled","askedPw":"0","askedPassphrase":"0","asked2fa":"0","askedHostKey":"1","gotUnrecognizedPrompt":"0","remoteInConfigFile":"1"},"measures":{"resolveAttempts":1,"retries":1}}
[14:03:29.823] ------

During the log in a Windows says Initializing VS Code Server. I'm not sure it means a connection was established or not.

3 Answers

Host ec2 HostName ec2-52-91-118-43.compute-1.amazonaws.com
User ec2-user IdentityFile ~/pathTopemFile.pem

this how my configuration file for ec2 host on vscode looks

The output says:

[14:03:27.444] Showing fingerprint confirmation dialog
[14:03:29.815] Fingerprint dialog canceled

I didn't notice the small dialog in the Command Palette area. I probably had too many Windows open.

When I accepted the fingerprint the connection was established. Accepting adds an entry in known_hosts . Meaning the dialog does not pop again, of course.

New VSCode Remote-SSH gives errors, a combination of 2 things worked for me:

  1. Revert to Remote-SSH 0.49 or before

  2. Change the permissions on the pem file to list user as the only owner and remove inheritance for other users. The config file IdentityFile parameter may automatically strip colons and dashes from the path, if you input it normally for the the Windows filesystem as C:\ it works for the IdentityFile setting.

After tons of trial and error Remote-SSH worked again, this time to Amazon EC2 running Ubuntu.

Related