How to use SSH credentials and GPG for dev container in vscode?

494 Views Asked by At

I am using VScode on macOS and are exploring dev containers to use for development to encapsulate all dependencies required to build my Go project. I created a dev container from my existing local Git repository and installed Ubuntu with Python and Go dependencies.

If I understand correctly, but local Git repository will be obsolete and my entire project will be moved into a container. How do I setup Git in that case? it is installed but doesn't have access to my local ~/.ssh or ~/.gnupg directory.

The VScode documentation has a page called Sharing Git credentials with your container and states it should work out of the box:

The Dev Containers extension provides out of the box support for using local Git credentials from inside a container. In this section, we'll walk through the two supported options.

My local .gitconfig has set user, email and signingkey. Still a push and pull within the container leads to:

[email protected]: Permission denied (publickey).

fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Can anyone help me?

1

There are 1 best solutions below

0
Tim Keegan On

I discovered via this answer that the setting terminal.integrated.inheritEnv must be set to true for the agent forwarding to work correctly.

Without this setting the SSH_AUTH_SOCK environment variable is not set in the devcontainer. After enabling Inherit Env and reopening the project in the devcontainer SSH_AUTH_SOCK should look something like: /tmp/vscode-ssh-auth-7c68defd-3baf-4a17-83e0-b4bc9d31eb12.sock