Open DerekHarter opened 2 years ago
Experiencing same issue on MacOS with M1 architecture, VS Code version 1.71.0
Try running ssh-add -l
on a host terminal, if the output is The agent has no identities.
then execute (also on host) ssh-add ~/.ssh/id_rsa
(or the path to your private key). Now the same command should list the key is successfully added. Then execute ssh-add -l
on the container terminal to see if the key was successfully shared. This sharing is done using the sockfile pointed by the SSH_AUTH_SOCK
env variable inside the container. VSCode should set it automatically.
Steps to Reproduce
For this issue, development in the repository/assignment appears normal. Can access git functionality in the VSCode Source Control side bar. Can create a commit. But when you go to push the commit will get something like a public key permission denied error:
Description
The ssh key appears to have been correctly created by the user/student. And the clone works because using the ssh key on the local host is working fine. But a push (or a clone) running inside of the DevContainer fails, as if the public/private ssh key is not available.
It is not clear why for some people the ssh key is shared or injected into the DevContainer, but in other installs it is not. I have yet to research how the local host ssh key is shared or injected into a Docker DevContainer. But in short, the local host ssh key has not been correctly copied or made available inside of the DevContainer, thus pushes or other git commands that contact the remote repository will fail.
Workarounds
The ssh key and git works fine on the local host. If you are cloning the repository normally, but then reopening in a DevContainer, the files and git repository are all shared/mounted between local host and container. So you can usually just simply open up a command terminal on the local host and perform a
Only commands that need to push or pull the remote origin (GitHub) will fail in the DevContainer, so can do the clone and push on the local host.
You can generate a new ssh key inside of the DevContainer
The key in the containers
/home/vscode/.ssh/id_rsa.pub
would then need to be added to the GitHub/Remote Repository ssh keys. This workaround would require you to generate a new ssh key for every assignment/DevContainer repository that is worked on.I did not try this yet, but in theory you could copy the
id_rsa
private key file from the local host to/home/vscode/.ssh/id_rsa
This would be a bit eaiser than 2 if it works, because would not have to constantly add new ssh keys to GitHub in this case.References