Search code examples
gitvisual-studio-codessh

How do I get a VSCode Remote - Containers devcontainer to use a forwarded SSH Agent for Git credentials?


In Microsoft's docs on sharing git credentials with a devcontainer they state:

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

However:

Locally:

I'm in OSX (Big Sur) and have an ssh agent running.

ssh-add -l gives:

256 SHA256:somelongkeyblahblah me@myemail.com (ED25519)

cat ~/.ssh/config gives:

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

In the remote container:

echo $SSH_AUTH_SOCK gives:

/tmp/vscode-ssh-auth-0fa193ba528678ff6157458207dbd1facaa44958.sock

ssh-add -l gives:

The agent has no identities.

cat ~/.ssh/config gives:

/bin/cat: /root/.ssh/config: No such file or directory

and ls -al ~/.ssh gives:

total 12
drwxr-xr-x 2 root root 4096 Jul 20 10:29 .
drwx------ 1 root root 4096 Jul 20 10:29 ..
-rw-r--r-- 1 root root  799 Jul 20 10:29 known_hosts

Question

Clearly, my ssh agent isn't being "automatically forwarded". I'm not very experienced in this area - what's my next move? How do I determine if this is due to something I've done, or due to a bug in Remote-Containers?


Solution

  • Just following up because it's been some time since I solved this, but (if memory serves me well) the problem was that my host wasn't set up to do agent forwarding - it was nothing to do with the devcontainer.

    I used these comprehensive instructions to set up agent forwarding and check its functionality.