DEV Community

Burke Holland
Burke Holland

Posted on

πŸš€ Introducing VS Code Remote Tunnels: Connect to Remote Machines with Ease!

Are you tired of constantly moving your code back and forth between your local machine and a remote server? Do you wish you could seamlessly develop on a remote machine without the hassle of SSH? Look no further! The Visual Studio Code Remote - Tunnels extension is here to solve your problems.

In today's fast-paced development world, it's becoming common to work on projects hosted on remote machines. Whether it's a powerful desktop PC or a virtual machine (VM), the Remote - Tunnels extension allows you to connect to it securely from your VS Code client anywhere.

But what exactly does "tunneling" mean? Tunneling is the process of securely transmitting data from one network to another. With the Remote - Tunnels extension, you can access your code and run commands directly on the remote machine, eliminating the need to have the source code on your local machine.

Sounds interesting, right? Let's explore how you can get started with the Remote - Tunnels extension.

πŸ› οΈ Getting Started: Two Paths to Remote Tunnels

There are two ways to work with tunnels using the Remote - Tunnels extension. You can either use the command-line interface (CLI) or enable tunneling through the VS Code Desktop UI. Both methods provide the same tunneling functionality, so you can choose the one that suits your workflow the best.

1️⃣ Using the 'code' CLI

If you prefer working with the command line, the code CLI is perfect for you. First, install the code CLI on the remote machine where you want to develop from your VS Code client. The CLI establishes a secure tunnel between your client and the remote machine. And the best part? The CLI is already built into the VS Code Desktop, so there's no additional setup required.

If you can't install the full VS Code Desktop on your remote machine, don't worry. You can download the CLI as a standalone installation from the VS Code download page. Alternatively, you can install and unpack the CLI through the terminal of your remote machine.

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

tar -xf vscode_cli.tar.gz
Enter fullscreen mode Exit fullscreen mode

Once you have the code CLI set up, creating a secure tunnel is as easy as running the following command:

code tunnel
Enter fullscreen mode Exit fullscreen mode

This command downloads and starts the VS Code Server on the remote machine and establishes a tunnel to it. You'll be provided with a vscode.dev URL tied to this remote machine, which you can open in any VS Code client.

2️⃣ Using the VS Code UI

If you prefer a more visual approach, you can enable tunneling through the VS Code Desktop UI. Simply open VS Code on the remote machine where you want to enable tunnel access.

From the VS Code Account menu, select the option to "Turn on Remote Tunnel Access." Alternatively, you can open the Command Palette (F1) and run the command "Remote Tunnels: Turn on Remote Tunnel Access."

A screenshot of the "Enable Remote Tunnels" option in VS Code

After logging into your GitHub account, a tunnel will start up on your current machine, allowing you to connect to it remotely. You can open the vscode.dev link from the notification and start coding in the remote environment.

πŸ”’ Secure and Convenient: The Remote - Tunnels Extension

By now, you might be wondering how the Remote - Tunnels extension fits into all of this. Well, when you open a vscode.dev instance through either the code CLI or VS Code UI, the Remote - Tunnels extension is automatically preinstalled.

If you're already working in VS Code (desktop or web) and want to connect to a remote tunnel, you can install and use the Remote - Tunnels extension directly. Once installed, you can connect to any remote machines with an active tunnel through the Command Palette.

The Remote Explorer view allows you to see your remote machines and easily manage the tunnel connections. You can focus on the Remote Explorer using the command "Remote Explorer: Focus on Remote View." The green remote indicator in the lower-left corner of the VS Code window also provides quick access to Remote Tunnels commands.

A screenshot of the Remote Tunnels explorer in VS Code

🌐 Common Questions: Answers You've Been Looking For

  1. What is the relationship between Remote Tunnels, VS Code Server, and Remote Development?

Remote Development allows your local VS Code installation to seamlessly interact with source code and runtime environments on other machines, whether virtual or physical. The VS Code Server, which is quickly installed by VS Code when you connect to a remote endpoint, enables this interaction. The Remote - Tunnels extension facilitates the connection to the remote machine where the VS Code Server is running.

  1. Can multiple users or clients access the same remote instance simultaneously?

No, an instance of the VS Code Server can only be accessed by one user or client at a time.

  1. How do I remove a tunnel or machine?

To stop a tunnel, you can use the shortcut Ctrl + C if you're running the CLI. In the VS Code UI, you can run the command "Remote Tunnels: Turn off Remote Tunnel Access..." to disable tunneling. To remove a machine's association with tunneling, you can use the "code tunnel unregister" command, or unregister it directly from the Remote Explorer view.

  1. How secure are the tunnels?

Accessing a tunnel requires authentication with your GitHub or Microsoft account. Once you connect from a remote VS Code instance, an SSH connection is established over the tunnel, providing end-to-end encryption using AES 256 in CTR mode.

🚦 Usage Limits: Everything You Need to Know

To prevent abuse, there are usage limits in place for resources like the number of tunnels and bandwidth. However, most users will never reach these limits. For example, at the moment, you can have up to 5 tunnels registered for your account. If you want to create a new tunnel and already have 5 others registered, the CLI will automatically pick a random unused tunnel and delete it.

If you require additional usage beyond the limits, you can get in touch with the team at vscodeserver@microsoft.com.

πŸ’‘ Conclusion: Simplify Your Remote Development Workflow Today!

The Visual Studio Code Remote - Tunnels extension is a game-changer for developers who work with remote machines. It streamlines the process of connecting to remote environments, allowing you to focus on what matters most: your code.

No more syncing code between machines or dealing with the complexities of SSH. With the Remote - Tunnels extension, you can seamlessly develop on any remote machine with ease. Whether you choose the CLI or the VS Code UI, connecting to a remote machine has never been simpler.

So go ahead, give it a try. Install the extension, create a tunnel, and experience the power of remote development firsthand.

Happy coding!

Full Disclosure: This post was written with the help of gpt-3.5turbo-16k.

Top comments (0)