Configuring SSH to work with VSCode dev containers was not straight forward. Through much trial and error I was finally able to establish SSH connections within the container without having to copy the SSH keys manually. I first started unraveling everything after finding a link to Advanced Container Configuration.
The error I was seeing had the following in it after starting a dev container:
[error] connect ENOENT \.\pipe\openssh-ssh-agent: Error: connect ENOENT \.\pipe\openssh-ssh-agent
I could still navigate the environment and use the terminal, but I did not have access via SSH without manually copying my private and public SSH keys into the containerized environment. The following steps give your dev container access to your ssh keys without any extra work or modifications to your container build.
OpenSSH key management gives the steps to install ssh-agent. I've distilled the necessary steps below.
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# Install the OpenSSHUtils module to the server. This will be valuable when deploying user keys.
Install-Module -Force OpenSSHUtils -Scope AllUsers
# Start the ssh-agent service to preserve the server keys
# If the command does not work, use the Services GUI to enable and start the agent
Start-Service ssh-agent
Get-Service -Name ssh-agent | Set-Service -StartupType Automatic
You can verify the services are installed correctly through the services GUI. Check that the listed services are both running and configured with Startup type: Automatic
.
- Win + R: "services.msc"
- OpenSSH Authentication Agent (ssh-agent)
Add one or more of your private keys into ssh-agent.
# example: add default private key
ssh-add C:\Users\some_user\.ssh\id_rsa
You can test your connection from within the VSCode dev container.
ssh -T [email protected]
# you should see a response similar to this
Hi <your_login>! You've successfully authenticated, but GitHub does not provide shell access.
This are several links used to narrow in on the problem and solution.
- https://github.com/microsoft/vscode-docs/blob/master/docs/remote/containers-advanced.md
- https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse
- PowerShell/Win32-OpenSSH#1586
- microsoft/vscode-remote-release#106
- https://superuser.com/questions/1327633/how-to-maintain-ssh-agent-login-session-with-windows-10s-new-openssh-and-powers
- https://laptrinhx.com/forwards-the-host-s-ssh-agent-into-a-docker-container-1941777776/