Loading...
Random Pearls Random Pearls New Menu
  • All Pearls
    • Random Pearls
  • Coding and Development - Reference …
    • Coding and Development - Reference …  (parent page)
    • Information Technology  (parent page of Coding and Development - Reference …)
  • New Menu
  • Authors
  •  
  • Contact Us
  • Sign up
  • Login
    Forgot Password?
  • Follow us on
Image Back to Top Back to top
Language Preference
This website has language specific content. Here you can set the language(s) of your preference.

This setting does not affect the current page. It is used only for filtering pages in menus, preview tiles and search results.

It can be changed any time by using the login menu (if you are logged in) or by clicking the Language button on the left bottom of the page.
Log in to save your preference permanently.



If you do not set this preference, you may see a header like This page has 'language_name' content in page preview tiles.
Search
  • Navigation
  • Similar
  • Author
  • More...
You are here:
All Content / Science and Technology / Information Technology / Coding and Development - Reference … / VS Code Remote Explorer + SSH + Password-less Login
Table of Contents

Subscribe to Our Newsletter
Follow us by subscribing to our newsletter and navigate to the newly added content on this website directly from your inbox!
Login to subscribe to this page.
Categories  
Tags  
Author  
manisar
Author's Display Image

"Whenever you can, share. You never know who all will be able to see far away standing upon your shoulders!"

I write mainly on topics related to science and technology.

Sometimes, I create tools and animation.


VS Code Remote Explorer + SSH + Password-less Login

July 7, 2022

Author - manisar

Some Important Tweaks


VS Code is one of the most popular modern IDEs.

One of its very cool features is remote development, that too from Windows host to remote Linux client in a seamless and elegant way!

Below, I'm providing a few simple tweaks to make your experience even more pleasant if you want to develop on a Linux machine remotely from your local Windows.

VS Code has a Self-installing Server!

That works even on Linux!

If you have VS Code running on your Windows machine and you use it for local development, there is no client-server architecture in picture.

But if you want to have your VS Code show code residing on a remote server, you need a VS Code server running remotely (which will be connecting to your local VS Code).

The good news is that VS Code can install its server automatically once you are connected to the remote machine (via VS Code). I've done it on multiple Linux systems, ranging from CentOS to Debian (including Raspberrypi OS), and never had any problem.

Let's see how we do this, and also make some other changes for making our connection automatic.

Note: It's a common practice to call the remote machine client. Just be aware that VS Code will install and run VS Code server on the (remote) client which makes the VS Code on your local machine, the client! Confusing, eh?

Well, it's just a naming thing.
I think, it's partly for avoiding this confusion, on the official page, they just call the local VS Code
VS Code (and not VS Code client)!

VSC Remote Explorer

This is how the Remote Explorer icon looks that we can see on the left hand side drawer in VS Code - this comes with VS Code.

This Remote Explorer needs one of these few extensions to be able to make any connections:

  • Remote - SSH - This is what we'll be looking at in this article.
  • Remote - Containers - This lets us connect to docker containers running on our local or remote machines.
  • Remote - WSL - This lets us connect to Linux virtual machines (WSL machines) running on the host computer - we've talked about this here - What's up with VS Code Remote, WSL, Docker and Dev-containers?.

More information about all these extensions can be found on the official page - VS Code Remote Development.

Let's find the Remote - SSH extension in the extensions wizard and install it.

And then go to the Remote Explorer by clicking on its icon.

I installed all the three extensions mentioned above, hence I see these three entries in the dropdown in the Remote Explorer window as shown below, viz:

  • Containers
  • WSL Targets
  • SSH Targets

Let's click on SSH Targets.

We are now in the SSH TARGETS window, and we now need to press the + icon on the top-right (-ish).
Note that you may need to hover your mouse over this window to make the + icon appear.

This gives us the prompt shown below.

At this point you may simply provide the connection command, in the form ssh user@host.

This will connect to the remote host, and immediately start installing the VS Code server!

Not that this may take some time.

Once this is complete, you get to work on your code that is sitting on the remote (Linux) machine, and you can even run and debug it!

The only slight discomfort with the setup we have done so far is that we'll be prompted for the connection credentials quite often.

I'm not sure but it seems there is an expiry of the connection we get this way.

We'll fix it now.

Let's Seal the Deal with Password-less Login

It becomes slightly tricky at this point as simply clicking on the + icon won't give you any other option than entering the credentials in the form of ssh user@host.

At the bottom-left, you'll see an icon as shown in green background below - like this:
>< .

Click on that, and you'll be presented with a plethora of remote connection options. From these, we need to select Connect to Host... .

This will give us the prompt we intend to see - Select configured SSH host or enter user@host.

What is happening here is that VS Code automatically tries to detect an SSH config file on the host machine, and use the entries from there.

The default location of the SSH config file on Windows is C:\Users\<username>\.ssh\config.

So, if you have configured this file with, e.g. public key authentication for a specific remote client, VS Code will not only show you that entry, it will also allow you to make a public-key based authentication based connection to the remote client!

You can see in the screenshot below the two entries that I've configured for myself in my SSH config.
Note that it's not a requirement for these pre-configured connections to use public-key authentication. SSH config primarily gives us the option of sugar-coating user@host command with some customization. Having publickey authentication is an extra.

PublicKey and SSH Config Permissions

You won't be able to make connections using public key until you ensure that a couple of settings/permissions are set as explained below:

  1. If you haven't done it before, you need to generate a publickey-privatekey pair.
    I generally use PuTTYgen for that.
    The public key needs to be added to the .ssh/authorized_keys file (on remote), and the private key is to be stored somewhere on your host machine.

  2. The private key must be in OpenSSH format.
    If you have created one using PuTTYgen, that is good for PuTTY, but not for the Windows SSH client.
    PuTTYgen has the option of exporting the private key to OpenSSH format which you must exercise.

  3. The last bit is about the permissions of the folder containing your private key.
    If not set properly, the connection will not work. Do as explained below:

    Private key folder --> Right click --> Properties --> Security --> Advanced --> Disable Inheritance --> Apply* --> Remove System and Administrator (and any other than yourself).

    * While disabling inheritance, it will give two options (as shown on the right):
    - Convert inherited permissions into explicit permissions on this object.
    - Remove all inherited permissions from this object.

    Only the first one worked for me.

With these settings, your VS Code should be able to make automatic connections to your remote machine.

Note that you'll even be able to install many of the VS Code extensions on the remote machine as well, e.g. the Python extension.

You'll get to see the option of install on <remote> while browsing the extensions when connected to a remote host.

Advertisement

VS Code Remote Server Architecture

While the picture below show a Container box on the right, it works pretty much similarly when you are connecting to a remote machine instead of a container.

VS Code Container Architecture

Advertisement
Close ad Ad

Advertisement
Close ad Ad

Return to Coding and Development - Reference and Tools

Tell us what you think (select text for formatting, or click )

Copyright © randompearls.com 2020

Privacy Policy