Forum Navigation
You need to log in to create posts and topics.

Visual Studio Code - SSH Keys not working

Visual studio code allows to you to do remote development with SSH Targets. but every time you connect to remote machine or session gets disconnected VScode prompts for password. all the tutorials seems to show easy exchange SSH keys in order to avoid the password prompt but its not working!!! when you are on windows trying to connect to Linux machine. even if you are using WSL (Windows Subsystem Linux) you can encounter this problem when trying to connect with SSH key exchange

The Problem

Main reason is when you doing ssh-copy-id from Windows to Linux Machine it adds extra values for the hostname in  $HOME/.ssh/authorized_kyes Example: ecdsa-sha2-nist…………………..JOWuiA== root@MyLovelyPC-2020-09-04

Solution

order to fix it copy the SSH public key manully

run the following commands on your windows machine (either in WSL or install ssh utilities)

ssh-keygen -t rsa -b 4096
scp .ssh/id_rsa.pub username@192.168.1.1

ssh to remote host

cd .ssh/
cat ../id_rsa.pub >> authorized_keys

NOTE: This issue is relevant not just for VScode but also to any remote development without password

if you are using WSL linux on your windows machine. open your SSH config in Visual Studio code and in the host add the following lin

ForwardAgent yes
PreferredAuthentications publickey
IdentityFile ~\\.ssh\\id_rsa

Make sure the following permissions are set

.ssh folder: 700 (drwx------)
public key: 644 (-rw-r--r--)
private key: 600 (-rw-------)

chmod g-w /home/user
chmod 700 /home/user/.ssh
chmod 600 /home/user/.ssh/authorized_keys


Note:

if you generated your ssh keys inside WSL linux. make sure also to copy them to your home user directory

cp ~USERNAME/.ssh/id_rsa* /mnt/c/Users/USERNAME/.ssh

and set proper permissions