Search code examples
visual-studio-codevscode-remote

VS Code ask for password repeatedly when opening different folder on same host


I have connected to a remote Ubuntu host from Windows using VS Code and using it for remote development. Often times I open different code repositories in VS Code but every time I have to open a different folder despite having the connection established the VS Code ask for password.

It seems that once we are commented to a remote host then successive opening of different folder from same host should not prompt for password.

Is there any setting I am missing or should do to resolve this or save password.


Solution

  • I'm assuming you're connecting to an ssh remote.

    There are two ways to authenticate an ssh connection, via password and via public/private key. When using the latter you don't need to enter the password each time.

    To use the public/private keys here's what you have to do:

    • You first need a pair (public/private) of ssh keys. On windows you can use ssh-keygen to generate them for you and put them in the default ssh config folder ( ~/.ssh/)
    • You then have to configure the remote server to allow your ssh key, you can do this in two ways:
      • with the ssh-copy-id command if available (I think on windows it's not there, but you can try)
      • by manually add your public key (~/.ssh/id_rsa.pub) to the.ssh/authorized_keys file on the host machine

    Here's a link to know more about passwordless logins via ssh: https://www.redhat.com/sysadmin/passwordless-ssh