I have setup a VS Code dev container and I can run and debug my code inside. My ~/.gitconfig from my host system was correctly copied into the container. However, my ssh credentials don't seem to work (or are not available), neither are my gnupg signing files (~/.gnupg) available.
Must I manually copy these files ( ~/.ssh and ~/.gnupg) into the container?
The documentation cautions:
There are some cases when you may be cloning your repository using SSH keys instead of a credential helper. To enable this scenario, the extension will automatically forward your local SSH agent if one is running.
The only stated requirement is the SSH-agent server running on my host system, which it is:
C:\Windows\system32> Get-Service ssh-agent
Status Name DisplayName
------ ---- -----------
Running ssh-agent OpenSSH Authentication Agent
What is the correct way to make my SSH credentials available to my dev container?
It is also possible to achieve this with the mount capability of the devcontainer.json configuration file:
{
"name": "container name",
...
"remoteUser": "root",
"mounts": [
"source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached",
]
...
}
With my version of dev containers there is a folder
/home/vscode
The correct mount option is therefore
"mounts": [
"source=${localEnv:HOME}/.ssh,target=/home/vscode/.ssh,type=bind,consistency=cached",
]
extra info: I needed this, since I have two github accounts with two ssh keys. When only the ssh agent is forwarded, git is picking up the wrong ssh key and authentication fails.
To solve this I added two hosts in the .ssh/config.
Host git_priv
Hostname github.com
IdentityFile ~/.ssh/id_rsa_git_private
IdentitiesOnly yes
Host github.com
Hostname github.com
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly yes
Basically I set one ssh key as standard (using github.com as the host) and the the other to only work with github-private.com as domain. If I now inlclude this git config with the above command into the devcontainer, I get the correct ssh key resolution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With