Some time ago I was working in a project that involved multiple Virtual Machines (VMs) and needed to access them via the ssh protocol. Before the beginning of the project, I never had done this kind of stuff, so I started to read about how to connect to a VM via ssh.
The process is really simple; however, it can be confusing at first, especially if you are used to remote connections on Windows through an application like PuTTY.
So for all of you who would like to start working with SSH but don’t know where to start, in this blog post I will show you how to connect to a VM with ssh from Windows.
This post is a follow-up to my previous post about setting up a VM using Vagrant and VirtualBox. In this post, I will be explaining how to connect to a virtual machine (VM) using ssh in Windows. This method can be used if you are connecting to a VM that has been set up through Vagrant, VirtualBox, or any other means.
This tutorial assumes you have already set up your VM and that you know where it is hosted. The instructions below have been tested with Ubuntu 18.04 LTS as the guest OS and Windows 10 as the host OS.
Install OpenSSH on Windows:
Windows 10 has an OpenSSH server installable through the Optional Features section of the settings app. Navigate to Settings > Apps > Manage optional features > Add Feature and select OpenSSH Client and then OpenSSH Server. To confirm your installation was successful, open a Command Prompt window and type ssh . If you see the help options for ssh , it has been installed successfully. If not, try re-installing it again by following these steps. Please note: Installing these windows features may require internet access or restarting your computer in order for them to work properly after installation.
This article describes how to set up and connect to an SSH/SFTP server on Windows.
1. Set up an SSH server in Windows
2. Connect to the VM using SSH on Windows
If you are running windows, there is a good chance that you need to connect to a VM (Virtual Machine) using an ssh connection. This tutorial will walk you through how to do it:
1. Make sure you have the latest version of Visual Studio Code installed.
2. Install the Remote Development extension pack in VS Code. This can be done by going to the extension view and installing the Remote Development extension pack.
3. Ensure that port 22 is open on your firewall by a quick google search for “check if port 22 is open”. If port 22 is blocked, then you will need to unblock it or allow exceptions for your firewall. You may also need to check with your network admin if any other ports need to be open.
4. Open up windows powershell as an administrator and run:
If you are using an OS other than Windows, you should use a native SSH command, rather than the Remote – SSH extension.
To connect to a Linux VM with SSH from Windows:
Install the Remote – SSH extension. For instructions, see Install Visual Studio Code Extensions.
Open the Command Palette (F1), and then type Remote-SSH: Connect to Host…
Enter your user name and host in the form user@host, and then select OK. The host is the full DNS name or IP address of the VM. You can also specify a port number by appending :port to the host name or IP address.
Authenticate with your private key or password as appropriate for the host machine and user name you entered.
SSH, or secure shell, is the most common way of administering remote Linux servers. It allows you to transfer files, install and run software on a remote server, and even automate tasks on your remote machines.
Setting up SSH on Windows
Step 1: Install a Windows Subsystem for Linux (WSL) Distro
Step 2: Install an OpenSSH Client for Windows
Step 3: Add the SSH Folder to Your PATH Environment Variable
Step 4: Connecting with SSH to VM-Series firewall in Google Cloud Platform (GCP)
Open the command prompt as administrator and type in the following command: ssh firstname.lastname@example.org -i C:\Users\tatest\Desktop\id_rsa
You will be prompted to enter the password and then you will be connected to the VM-Series firewall in Google Cloud Platform!
Connecting with SSH to your server can be very secure and prevents anyone from intercepting any of the data transferred between your local computer and your remote server.
This article assumes that you already have a basic working configuration of Windows 10 with WSL 2, a Windows Subsystem for Linux installation with access to an Ubuntu distro, and the VS Code Remote – WSL extension installed.
Connecting for the first time
You will need to connect to your VM instance for the first time using Google Cloud Platform’s web-based SSH connection tool. This will ensure that you have access to your VM instance and can generate a key pair for SSH connections.
In the Cloud Console, go to the VM instances page.
Go to the VM instances page
Click SSH in the list of instances.
Generate a new key pair by following these instructions. I recommend against using a passphrase as it adds an additional layer of complexity when connecting via SSH through Visual Studio Code.