Signing back into the Community for the first time? You'll need to reset your password to access your account. Find out more.
Forum Discussion
smfelsher
9 months agoOccasional Contributor
VSCode dev container and SSH
I am trying to use my SSH keys, which are stored in 1Password, in a dev container launched within VSCode.
Here is my ~/.ssh/config
```
Gitlab
Host gitlab.com
HostName gitlab.com ...
smfelsher
9 months agoOccasional Contributor
Yes, it should be IdentityAgent
!
Regarding your problem.
I think this will only work in a Dev Container by using the SSH_AUTH_SOCK environment variable. So, export SSH_AUTH_SOCK in your shell configuration file for WSL. If you're using bash
, then in .bashrc
put the following: export SSH_AUTH_SOCK="$HOME/.1password/agent.sock"
.
Now, launch VSCode, but before you start your dev container, see if your VSCode environment is seeing SSH_AUTH_SOCK. Open the integrated terminal in VSCode and see that SSH_AUTH_SOCK is set. If SSH_AUTH_SOCK is not set, you need to figure out how to set it before you launch your dev container. I believe VSCode will map the host SSH_AUTH_SOCK to a socket file in the container.
Oh, and one other thing that I forgot in my previous post! I have mapped my host ~/.ssh
directory into the container. Here is a snippet from my devcontainer.json
.
```json
"mounts": [
// Bind mount the developer's SSH directory to allow using SSH keys for
// GitLab. The target must be the home directory of the non-root user of the
// container.
{
"source": "${localEnv:HOME}/.ssh",
"target": "/home/node/.ssh",
"type": "bind"
}
]
```
I'm using a Node image and the non-root user, node
, in the container, so I'm mapping my .ssh
directory into the container user's home directory.
So,
- Your SSH config and keys must be mapped into the dev container, like on your host.
- VSCode will map the local SSH_AUTH_SOCK into the container if VSCode sees that SSH_AUTH_SOCK is set.
- Unless you have changed any of the Remote SSH settings in VSCode.
Let me know if I can help you further or if you figure it out!