visual-studio-codesshopensshssh-agentvscode-devcontainer

SSH ask for a password in VSCode Dev Container even if ssh-agent seems correctly configured?


I've configured Windows 11 ssh-agent following the official documentation and then used ssh-add to add my SSH keys:

PS> Get-Service ssh-agent

Status   Name               DisplayName
------   ----               -----------
Running  ssh-agent          OpenSSH Authentication Agent

Command ssh-add -l show the key (just 1):

PS > ssh-add -l
3072 SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Marco@PC-MARCO (RSA)

I can successfully connect to a remote machine (i.e. ssh user@remote.mydomain.com) using the SSH key from the Windows machine.

From the documentation:

[...] the extension will automatically forward your local SSH agent if one is running

In fact inside a Visual Studio Code WSL2 container, the ssh-add -l command show the same output:

vscode ➜ /workspaces/test-ssh-agent $ ssh-add -l
3072 SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Marco@PC-MARCO (RSA)

However inside the container the same exact command ssh user@remote.mydomain.com ask for a password.

It seems that it doesn't know that for that user/domain the stored SSH key should be used. Any help is much appreciated!

EDIT: this is the debug log, it can't find the private key (of course) because inside the container. What's the point of ssh-agent then?

debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/vscode/.ssh/id_rsa
debug3: no such identity: /home/vscode/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /home/vscode/.ssh/id_ecdsa
debug3: no such identity: /home/vscode/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/vscode/.ssh/id_ecdsa_sk
debug3: no such identity: /home/vscode/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /home/vscode/.ssh/id_ed25519
debug3: no such identity: /home/vscode/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /home/vscode/.ssh/id_ed25519_sk
debug3: no such identity: /home/vscode/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /home/vscode/.ssh/id_xmss
debug3: no such identity: /home/vscode/.ssh/id_xmss: No such file or directory
debug1: Trying private key: /home/vscode/.ssh/id_dsa
debug3: no such identity: /home/vscode/.ssh/id_dsa: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

Solution

  • I followed this guide and most importantly I updated OpenSSH to the latest version available here: https://github.com/PowerShell/Win32-OpenSSH/releases

    Now works without any problem.