Skip to content

Instantly share code, notes, and snippets.

@aspen-roller
Last active July 23, 2024 05:44
Show Gist options
  • Save aspen-roller/c2e0adf5d95e5da08bbec1815abe0e2c to your computer and use it in GitHub Desktop.
Save aspen-roller/c2e0adf5d95e5da08bbec1815abe0e2c to your computer and use it in GitHub Desktop.
VSCode: setup SSH on Win10 in DevContainer #vscode #ssh

Setup SSH for VSCode on Windows 10

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.

Install SSH Agent

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 SSH Keys

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

Verify SSH Connection

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.

References

This are several links used to narrow in on the problem and solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment