Pages

Tuesday, May 02, 2023

VS Code Connect to host Remote SSH invalid format Permission denied (publickey)

After moved a website from one AWS ubuntu EC2 instance to a another AWS ubuntu ECS instance I wanted to make some quick modifications to some python code there.

Using VS Code, I created a new host in my C:\users\Administrator\.ssh\config file using the same format as my previously working host config:

Host XX.XXX.XX.XXX
  HostName XX.XXX.XX.XXX
  User ubuntu
  IdentityFile "C:/Users/Administrator/Documents/Projects/TTS/key_that_works_with_putty.ppk"

Connecting using that host entry consistently returned in VS Code terminal:

[21:32:12.279] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 56925 "XX.XXX.XX.XXX" bash
[21:32:12.283] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[21:32:12.608] > ]0;C:\WINDOWS\System32\cmd.exe
[21:32:12.608] Got some output, clearing connection timeout
[21:32:12.957] > Load key "C:/Users/Administrator/Documents/Projects/TTS/key_that_works_with_putty.ppk" i
> nvalid format
[21:32:12.990] > ubuntu@XX.XXX.XX.XXX: Permission denied (publickey).

Although the key worked with putty and WinSCP, VS Code called it invalid and public.

The fix was:
  • puTTYgen
  • Load
  • point to key_that_works_with_putty.ppk
  • Conversions | Export OpenSSH key
  • Call the new key something like key_that_works_OpenSSH_style.ppk
  • Modify VS Code host entry IdentityFile to point to new key.

Hope that helps.

No comments:

Post a Comment