To set up SSH-Agent running inside a WSL distribution and connect to a remote server via Visual Studio Code, follow these steps:
- Install OpenSSH in your WSL distribution:
wsl --install -d <distro>
Replace <distro> with the name of your WSL distribution (e.g., Ubuntu).
- Open the WSL terminal and start the SSH-Agent:
eval "$(ssh-agent -s)"
- Add your SSH private key to the SSH-Agent:
ssh-add ~/.ssh/id_rsa
Replace id_rsa with the name of your SSH private key.
- Update your SSH config file to forward the agent connection:
nano ~/.ssh/config
Add the following lines to the config file:
Host *
ForwardAgent yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
Replace id_rsa with the name of your SSH private key.
- Install the Remote - SSH extension for Visual Studio Code:
- Open Visual Studio Code
- Go to the Extensions view (Ctrl+Shift+X)
- Search for "Remote - SSH"
- Install the extension
- Connect to your remote server:
- Click on the Remote-SSH icon in the Activity Bar
- Click on "Open Folder in New Window"
- Navigate to the directory you want to access on the remote server
- Click on "Open"
Now you should be connected to your remote server via Visual Studio Code, and your SSH-Agent will automatically forward the authentication for you.
References: