'Why asking password VS Code Remote SSH plugin if I use public key to authenticate?

I just started using Remote - SSH (ms-vscode-remote.remote-ssh) plugin. I put this code into settings.json:

    "remote.SSH.remotePlatform": {
        "myserver": "linux"
    }

In the config file:

Host myhost
  HostName myhost
  User root
  IdentityFile ~/.ssh/id_rsa.pub

Exactly as the documentation said, and I expected - like in the PuTTY - the plugin just log in and done, but it still asking password for login.

Is there any setting what I missed? Or is there any setting what I must apply to avoid asking password?



Solution 1:[1]

You need to use the private key as mentioned below. Additionally, you need to copy the contents of your public key file (the one that ends with .pub), to a file called "authorized_keys", usually located under ~/.ssh

Solution 2:[2]

You are supposed to use the private key, if your public key is ~/.ssh/id_rsa.pub then the private key is probably ~/.ssh/id_rsa

Solution 3:[3]

For Windows 10, if you have stumbled across this issue using the Remote - SSH plugin, run the following in PowerShell (as admin):

# Make sure you're running PowerShell as an Administrator
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
Get-Service ssh-agent

And then if you already generated a key, do ssh-add. It should then prompt you for the passphrase of your key, then you should get a message that your key has been set as the default identity. Open up VSCode and try again.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 KotaKotik22
Solution 3 RobbieC