Exercise - Enable Remote - Tunnels in the code CLI

Completed 100 XP

In this exercise, you learn how to:

  • Create and use a tunnel through the code CLI.
  • Install the code CLI on a remote machine you intend to work on.
  • Establish a tunnel between a Visual Studio Code client and your remote machine by using the code CLI.

You can get the code CLI either from the Visual Studio Code download pane or through the command prompt.

Get the code CLI from the Visual Studio Code download pane

  1. Go to the Visual Studio Code download pane.

    Screenshot of the download pane.

  2. Download and extract the code CLI for your operating system into the TestCLI directory.

    1. After you download the file, you see that you have a compressed file.

    Screenshot of a compressed file.

    1. Double-click the file to extract it to the TestCLI directory, and you see the code file.

    Screenshot of an extracted code file.

  3. From the terminal, go to the TestCLI directory.

Install and unpack the code CLI through the terminal

If you don't have access to a user interface or the Visual Studio Code download pane, you can use the terminal to install the code CLI. After you create the TestCLI folder, use the following commands to install the code CLI from within the TestCLI directory in the terminal:

Bash
 curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz
Bash
tar -xf vscode_cli.tar.gz

Create a secure tunnel

  1. Run the following command to download and start the Visual Studio Code Server on this machine and then create a tunnel to it:

    Bash
    code tunnel --accept-server-license-terms
    
  2. Copy and save the provided link and code.

    Screenshot of link to sign in on client with code.

  3. On your client, open the previously saved link in a web browser and enter the code that was provided in your terminal. Select Continue to activate.

    Screenshot of the Device Activation pane.

  4. Select Continue to authenticate.

    Screenshot of the Single sign-on pane.

  5. Select Authorize.

    Screenshot of the authentication pane.

  6. You see a congratulatory message that indicates success.

    Screenshot of confirmation.

    The code CLI outputs a vscode.dev URL specific to this remote machine, such as https://vscode.dev/tunnel/<machine_name>/<folder_name>. Screenshot of a tunnel link for a client.

    This process authenticates you to the tunneling service and ensures that you have access to the designated remote machines.

  7. Open the URL on a client of your choice.

  8. Select Allow to give the Remote - Tunnels extension permission to sign in.

    Screenshot of the Remote - Tunnels extension permission to sign in.

  9. Select Yes, I trust the authors to give access to the folder.

    Screenshot of the prompt Yes, I trust the authors.

  10. Begin coding!

    Screenshot of code.


Next unit: Knowledge check

Previous Next