Visual Studio Code is a popular Integrated Developer Environment (IDE) for developers. Its large selection of plugins, minimal design, and cross-platform support make it a great choice for developers of all levels. This tutorial focuses on using the Remote-SSH plugin to enable remote software development. With this plugin you can edit files on your local workstation, but run development tasks such as program execution, unit tests, or static analysis on a remote server.
There are many reasons why this may be beneficial to you. For example, you may have a Windows workstation and want to develop on Windows, but your code will eventually run on Linux. You may need more RAM or processing power than your current machine has available, or you want to keep code off of your personal machine due to a company policy, or the desire to keep your workstation prestine.
In this tutorial, you’ll enable the Remote-SSH plugin, configure Visual Studio Code to execute code on the remote server, and execute code from your local Visual Studio Code installation on the remote server.
In order to follow along with this guide, you’ll need:
- A local development machine running Windows, MacOSX, or Linux. This tutorial will not work on ChromeOS devices.
- Visual Studio Code, which you can download and install from the official web site.
- An SSH key pair generated:
- If you’re using macOS or Linux, you can follow Step 1 from How to Set Up SSH Keys on Ubuntu 20.04. The commands are the same, so don’t worry that the tutorial says it is for Ubuntu 18.04.
- If you’re using Windows, follow the tutorial How to Create SSH Keys with PuTTY on Windows to create your SSH Key.
- If you’re using DigitalOcean, you can follow the How to Upload SSH Public Keys to a DigitalOcean Account guide.
- One Ubuntu 18.04 server set up by following the Ubuntu 18.04 initial server setup guide, including a non-root
sudo-enabled user and a firewall.
Step 1 — Installing the Remote-SSH Plugin
The Extensions Marketplace is where you can download supported and third-party extensions for a variety of different tools and programming languages. This is where you will search for the Remote-SSH plugin and install it.
On the left-hand side of the IDE there is a vertical row of five icons. The bottom icon, which looks like four squares in a box with the top right square exploding out, is the icon for the Extensions Marketplace:
You can also access this section by pressing
Ctrl+Shift+X. When you open this page you will see suggested plugins to download and install.
Once you have the Extensions Marketplace open, type
Remote-SSH in the Search Extensions in Marketplace search bar. When you find the plugin, select it and then click the green Install button to install the extension.
The extension is now installed. Next, you’ll configure the extension so you can connect to your server.
Step 2 — Configuring the Remote-SSH Plugin and Connecting To Your Server
Now that you have the plugin installed you can configure it to connect to a server. To do so, you’ll need the following pieces of information:
- The server’s IP or hostname.
- The username you’ll connect with.
- The private key you’ll use to authenticate your user.
You’ll use this information to create an SSH configuration file that Visual Studio Code can use to SSH to the server to sync files and execute code on your behalf. You will create this configuration using Visual Studio Code.
Now that you have the Remote-SSH plugin installed, you’ll see a small green box in the bottom left-hand corner of the Visual Studio Code interface. If you hover over the box with your mouse pointer, the popup will say Open a remote window. The button looks like a greater than sign slightly under a less than sign ><, like the one in the following image:
Click the button, and a dialog box appears in the top center. Select Remote-SSH: Open Configuration File… from the list:
The next prompt will ask you which configuration file you want to open. If you’re on Windows, you’ll see two locations: one in your personal user directory, and one in the installation location for SSH. You should use the file in your user directory when configuring the server.
Select the file and your editor will open the
config file. Add the following code to the file to define the connection to your server, replacing the highlighted sections with the information for your server:
Host my_remote_server HostName your_server_ip_or_hostname User sammy IdentityFile /location/of/your/private/key
Here’s how this configuration file works:
Host: This specifies a name for your host. This lets you use a short name or abbreviation instead of the full IP address or host name when connecting to the server.
HostName: The actual hostname of the server, which is either an IP address or a fully qualified domain name.
User: The user you want to use to connect with.
IdentityFile: The path to your SSH private key. On Mac and Linux systems, you’ll find this in your home directory in a hidden
.sshdirectory, typically called
id_rsa. If you are on Windows you will have specified a location to save this file when you created it using
Specify the appropriate values in your file and save the file.
Visual Studio Code is now configured and ready to connect to your server. Click on the green Open a remote window button in the bottom left-hand corner and select Remote-SSH: Connect to Host…
Once you’ve done this all the availble and configured servers will appear in the dropdown menu. Select the server that you want to connect to from this list.
If this is the first time you have connected to this server from your machine, you’ll likely be prompted with the SSH Fingerprint verification dialog, like the one in the following image:
This is to ensure that you are really connecting to the server you think you are. You can verify this by logging in to your server manually and running
ssh-keygen -l -f /etc/ssh/ssh_host_key.pub to view the fingerprint of the server. If this fingerprint is the same as the one being presented to you in Visual Studio Code, then you are indeed connecting to the server you think you are so you can click Continue.
Visual Studio Code defaults to opening a new window when a new connection is made. A new window will appear with the welcome screen. You’ll know that your connection was successful if you see
SSH: your_ip_address_or_hostname in the green box in the bottom left-hand corner. This means that Visual Studio Code is connected and communicating with your remote server.
Now that you’re connected, you can run commands and code from your editor.
Step 3 — Executing Code on the Remote Server
The Remote-SSH plugin is configured, and it’s time to run some code on your remote machine. Open a terminal window by selecting Terminal from the navigation bar at the top of the Visual Studio window and clicking New Terminal. You can also open a terminal by pressing
CTRL+Shift+`. The terminal that is opened is a terminal on your remote server, not one on your local machine.
When the terminal opens, issue the following command to view the IP address of your server to verify that you are connected to your remote server:
- ip addr
You’ll see the following output in your terminal:
Output1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 16:cb:05:5b:30:f1 brd ff:ff:ff:ff:ff:ff inet your_server_ip brd your_broadcast_address scope global eth0 valid_lft forever preferred_lft forever ...
To test out the ability to run remote code, create a new Python file called
hello.py in your editor. When you are connected to your remote server, all files created through Visual Studio Code will be saved to that server, not on your local machine.
Add the following contents to the file:
To run this program on your server, open a terminal in Visual Studio Code from the navigation menu or by pressing the key sequence
CTRL+Shift+`. Since this terminal session is connected to your remote server, run the following command in the terminal to execute your
- python3 hello.py
Your program’s output will be displayed.
You can also execute the file from the Debug context menu by selecting Run without Debugging.
Note: If you have any development extensions installed in Visual Studio Code, like the Python extension, you will have to reinstall these extensions on your server through the Extension Marketplace. If you have previously installed these plugins in Visual Studio Code, when you search for them again, the Marketplace will say Install on SSH: hostname. Always pay attention to what devlopment context you are in, because this is where Visual Studio Code will install your plugins and create your files. If you try to run your code without these plugins installed, error dialog boxes will appear in the bottom right-hand corner of the screen prompting you to install them on your remote server. After you have installed these they will likely require you to reload Visual Studio Code. When you relaunch it, it will continue working on the remote server without you having to manually reconnect.
You now have Visual Studio Code configured for development on a remote server using SSH. Remote execution with an IDE provides many benefits, including the ability to quickly test how your code runs on different operating systems and different hardware specifications. As long as you have an internet connection you could connect to your server and work on your code from any computer, and you’ll be able to develop using a Linux environment even if you run Windows as your primary operating system.
Connect to a remote host
In VS Code, select Remote-SSH: Connect to Host... from the Command Palette (F1, Ctrl+Shift+P) and use the same user@hostname as in step 1. If VS Code cannot automatically detect the type of server you are connecting to, you will be asked to select the type manually.
- In Visual Studio, choose Tools > Options on the menu bar to open the Options dialog. ...
- In the Connection Manager dialog, choose the Add button to add a new connection. ...
- Enter the following information: ...
- Choose the Connect button to attempt a connection to the remote computer.
The tutorials below will walk you through running Visual Studio Code with the Remote Development extensions. Connect to remote and virtual machines with Visual Studio Code via SSH. Run Visual Studio Code in Windows Subsystem for Linux. Run Visual Studio Code in a Docker Container.
To initiate an SSH connection to a remote system, you need the Internet Protocol (IP) address or hostname of the remote server and a valid username. You can connect using a password or a private and public key pair. Because passwords and usernames can be brute-forced, it's recommended to use SSH keys.How do you configure Visual Studio code to remote SSH to an AWS instance? ›
- You can find your AWS credentials under AWS Details of your AWS Academy account.
- Download the SSH key (labsuser.pem) file to your local computer. ...
- Open up Visual Studio Code.
- Click on the Open a Remote Window icon at the bottom left-hand corner of the window.
- Select Connect to Host.
Launching from the command line
You can also run VS Code from the terminal by typing 'code' after adding it to the path: Launch VS Code. Open the Command Palette (Cmd+Shift+P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.
You can connect over SSH into another machine from Visual Studio Code and interact with files and folders anywhere on that remote filesystem. If you have an app located on a different computer, you could use SSH to connect to it and access your app, view its files, and even modify, run, and debug it.How do I run a script on a remote server? ›
To run a script on one or many remote computers, use the FilePath parameter of the Invoke-Command cmdlet. The script must be on or accessible to your local computer. The results are returned to your local computer.How do I setup a remote server connection? ›
- Click the Start button.
- Click Run...
- Type “mstsc” and press the Enter key.
- Next to Computer: type in the IP address of your server.
- Click Connect.
- If all goes well, you will see the Windows login prompt.
You can install extensions manually without an internet connection using the Extensions: Install from VSIX... command, but if you use the extension panel or devcontainer. json to install extensions, your local machine and VS Code Server will need outbound HTTPS (port 443) access to: marketplace.visualstudio.com.
- First connect your device trough USB.
- Run ADB:📱 Disconnect from any devices.
- And run ADB:📱 Reset connected devices port to :5555.
- And Then ADB:📱 Connect to device IP enter your device (settings > status > ip address) IP address and be fine.
- Open VS Code.
- To open the Command Palette, on the menu bar, choose View, Command Palette. ...
- Search for AWS and choose AWS Toolkit Connect to AWS.
- Choose a profile from the list. ...
- Open the AWS Toolkit Explorer Side Bar, which we call the AWS Explorer, to verify the connection.
SSH encrypts and authenticates all connections. SSH provides IT and information security (infosec) professionals with a secure mechanism to manage SSH clients remotely. Rather than requiring password authentication to initialize a connection between an SSH client and server, SSH authenticates the devices themselves.What is SSH remote command? ›
SSH Remote Command allows a connection with a SSH server to be established and that shell scripts to be executed. Take a look at the configuration parameters of the component: Account: for the component to make an authentication to a SFTP server, it's necessary to use a BASIC or PRIVATE-KEY-type account.How do I enable SSH connections? ›
- Connect to the server via SSH.
- Escalate privileges to 'root': ...
- Set password for 'root' user: ...
- Make sure that the configuration file /etc/ssh/sshd_config has parameters PermitRootLogin and PasswordAuthentication are set to yes and not prepended by # symbol.
The AWS Toolkit for Visual Studio conveniently includes the AWS SDK for . NET, so you can get started building . NET applications on AWS infrastructure services in Visual Studio, including Amazon S3, Amazon EC2, AWS Elastic Beanstalk, and Amazon DynamoDB.How do I connect to an EC2 instance via SSH? ›
- Open your terminal and change directory with command cd, where you downloaded your pem file. ...
- Type the SSH command with this structure: ssh -i file.pem username@ip-address. ...
- After pressing enter, a question will prompt to add the host to your known_hosts file. ...
- And that's it!
EC2 Instance Connect provides a simple and secure way to connect to your EC2 instances using one-time SSH keys.Does Visual Studio code have a console? ›
Select Run > Step Into or press F11 . Visual Studio Code runs the Console.How do I call a Visual Studio code from terminal in Linux? ›
Launching VS Code from the terminal looks cool. To do this, press CMD + SHIFT + P, type shell command and select Install code command in path. Afterwards, navigate to any project from the terminal and type code . from the directory to launch the project using VS Code.
If you want direct access to the virtual machines in your service instance, set up an SSH client so that you can run commands from your local machine. Download and install an SSH client on your local machine. Find the VM IP address and private key.Can I run SSH command on Windows? ›
You can start an SSH session in your command prompt by executing ssh user@machine and you will be prompted to enter your password. You can create a Windows Terminal profile that does this on startup by adding the commandline setting to a profile in your settings.How do I connect to SSH from Windows? ›
- Open a Command prompt window on your technician PC.
- Connect to the device: To connect using a username and password: cmd Copy. ssh user@192. 168. ...
- Enter the password for your user if you're connecting with a username and password, or if you configured your key to require a password.
The Solution: Pass The Script Over Standard Input
The bash -s command means “execute the following commands in a new bash session.” The -s flag makes it read from standard input, and the < script.sh bit will read a local script file into standard input.
- On the computer where you want to run the automation script, select Start > Run. ...
- Enter dcomcnfg and click OK. ...
- Select QuickTest Professional Automation from the DCOM Config list and open the Properties dialog box for the application.
- Gets UserName and Password from the User.
- Read the list of server names from a Serverlist.properties file.
- Create a Script on the Runtime named TestScript.sh using HereDocument.
- Copy the Created TestScript to the remote server using SCP.
- Comparison of Top Remote Access Tools.
- #1) NinjaOne (Formerly NinjaRMM)
- #2) SolarWinds Dameware Remote Support.
- #3) Atera.
- #4) Supremo.
- #5) ManageEngine Remote Access Plus.
- #6) RemotePC.
- #7) TeamViewer.
In the Terminal app on your Mac, choose Shell > New Remote Connection. Select a protocol in the Service list. Select a shared server in the Server list. In the User field, enter a user name, then click Connect.How can I access my computer remotely? ›
- On your Android phone or tablet, open the Chrome Remote Desktop app. . ...
- Tap the computer you want to access from the list. If a computer is dimmed, it's offline or unavailable.
- You can control the computer in two different modes.
Visual Studio vs Visual Studio Code - Differences
Visual Studio is an Integrated Development Environment, also known as an IDE. Visual Studio Code is a code editor. A developer can easily edit their code. VS is slower when it comes to performing across different platforms.
- Sublime Text.
- GNU Emacs.
Install a compiler
VS Code is first and foremost an editor, and relies on command-line tools to do much of the development workflow. The C/C++ extension does not include a C++ compiler or debugger. You will need to install these tools or use those already installed on your computer.
You can browse and install extensions from within VS Code. Bring up the Extensions view by clicking on the Extensions icon in the Activity Bar on the side of VS Code or the View: Extensions command (Ctrl+Shift+X). This will show you a list of the most popular VS Code extensions on the VS Code Marketplace.How do I share my VS Code project? ›
If you select Start Collaboration session from the Session Details menu, an invitation link to your session will automatically be copied to your clipboard. You can share this link with anyone you'd like to collaborate with, as long as they also have VS Code and the Live Share Extension Pack downloaded.How do I run code in VS Code Live share? ›
Press CTRL+SHIFT+P in VSCode to open the command palette, as shown below. Enter Start Collaboration Session and select liveshare. start from the list. Click OK when you get a pop-up message to accept unblocking ports on your firewall.How install AWS CLI in VS Code? ›
- Start the VS Code editor.
- In the Activity Bar on the side of the VS Code editor, choose the Extensions icon. ...
- In the search box for Extensions, search for AWS Toolkit. ...
- In the right pane, choose Install.
The AWS Toolkit for Visual Studio Code is an open source plug-in for the Visual Studio Code that makes it easier to create, debug, and deploy applications on Amazon Web Services.What is difference between SSH and SSH? ›
The main difference is that sshd is a server (like a web server serving https) and SSH is a client (think of a web browser). The client/user authenticates itself against the server using the users credentials.How does SSH works step by step? ›
SSH consists of three distinct layers: The transport layer establishes safe and secure communication between a client and a server during and after authentication. It oversees data encryption, decryption, and integrity protection. Furthermore, it helps speed up data exchange by providing data compression and caching.Is remote SSH safe? ›
SSH is a widely-used protocol used for accessing Linux servers securely. Most users use SSH connections with default settings to connect to a remote server. However, the unsecured default configurations also pose various security risks. The root account of a server with open SSH access may be at risk.
The SSH key pair is used to authenticate the identity of a user or process that wants to access a remote system using the SSH protocol. The public key is used by both the user and the remote server to encrypt messages. On the remote server side, it is saved in a file that contains a list of all authorized public keys.What is SSH agent used for? ›
The ssh-agent is a helper program that keeps track of user's identity keys and their passphrases. The agent can then use the keys to log into other servers without having the user type in a password or passphrase again. This implements a form of single sign-on (SSO).How do I check if SSH port is enabled? ›
- $ grep -i port /etc/ssh/sshd_config.
- $ sudo nano /etc/ssh/sshd_config.
- $ ssh -p <port_number> <username>@<ip_address>
Step 1: Check if SSH is enabled
To check if SSH is enabled on your system, open a command prompt and end the command ssh . If it provides you with help for using SSH, it is already enabled! You should be able to follow the Linux instructions using the ssh-keygen command from the command prompt.
- sudo rm -f /etc/ssh/sshd_not_to_be_run sudo systemctl enable ssh sudo systemctl start ssh.
- sudo mv /etc/init/ssh.conf.back /etc/init/ssh.conf sudo start ssh.
- sudo systemctl stop ssh sudo systemctl disable ssh.
- sudo stop ssh sudo mv /etc/init/ssh.conf /etc/init/ssh.conf.back.
- Download Visual Studio Code for Linux.
- Make a new folder and extract VSCode-linux-x64. zip inside that folder.
- Double click on Code to run Visual Studio Code.
You can start an SSH session in your command prompt by executing ssh user@machine and you will be prompted to enter your password. You can create a Windows Terminal profile that does this on startup by adding the commandline setting to a profile in your settings.Can we run Linux commands in Visual Studio Code? ›
You can use the store app, or search for a Linux distro in the Windows search bar. Choose the Linux distribution you want to install (for example Ubuntu) and follow the prompts. Select Install. And when done, select Launch to get started.Can you use Visual Studio Code on Linux? ›
VS Code runs on macOS, Linux, and Windows.Is there Visual Studio Code for Linux? ›
VS Code is a free code editor, which runs on the macOS, Linux, and Windows operating systems. Follow the platform-specific guides below: macOS.