How to SSH Connect to Remote Ubuntu from a Windows VScode Host

Connecting to a remote Ubuntu server from a Windows host is a common task for many developers and system administrators. In this guide, we'll walk you through the process step by step.



Step 1: Generating SSH Keys on Windows

The first step is to generate SSH keys on your Windows machine. SSH keys are used for secure authentication when connecting to remote servers. Here's how to do it:

  1. Open the Windows Start menu and search for "Apps & Features."
  2. Under the "Apps & Features" heading, click on "Optional Features."
  3. Scroll down the list and check if "OpenSSH Client" is listed. If not, click the plus sign next to "Add a feature," select "OpenSSH Client," and click "Install."
  4. Open a command prompt or PowerShell window.
  5. Type the following command and press Enter to generate an SSH key:
ssh-keygen -t ed25519

By default, the system will save the keys to [your home directory]/.ssh/id_ed25519.pub. It will also create a private key.

Step 2: Copy the Public Key to the Remote Ubuntu Server

To connect to the remote Ubuntu server, you need to copy the public key to the server's ~/.ssh/authorized_keys file. Here's how:

  1. Securely transfer the public key to the remote server. You can use tools like scp or manually copy the key and paste it into the ~/.ssh/authorized_keys file on the remote server.

Step 3: Create a Config File on Windows

To simplify the connection process, you can create a configuration file on your Windows machine. This file specifies the connection details for your remote server. Here's an example of what your config file could look like:

In Windows, create a file named config in the user/.ssh/ directory (e.g., C:\Users\DESKTOP_USER\.ssh\config) and add the following content:

Host EXAMPLE_NAME
    HostName IP_ADDRESS_HERE
    User USERNAME
    Port 22
    IdentityFile C:\Users\DESKTOP_USER\.ssh\id_ed25519
    PreferredAuthentications publickey

Replace EXAMPLE_NAME, IP_ADDRESS_HERE, USERNAME, and the path to the private key file with your specific information.

Step 4: Use VSCode Remote Extension

Now that you've set up your SSH keys and configuration file, you can use Visual Studio Code's Remote Development extension to connect to your remote Ubuntu server seamlessly.

  1. Open VSCode on your Windows machine.
  2. Install the "Remote - SSH" extension if you haven't already.
  3. Click on the "Remote Explorer" icon in the VSCode sidebar.
  4. Under "SSH Targets," click the "Configure SSH Hosts" button.
  5. Add a new configuration by entering the hostname you specified in your config file (e.g., EXAMPLE_NAME).
  6. Connect to the remote server by clicking on the hostname in the Remote Explorer.

You're now connected to your remote Ubuntu server from your Windows host using SSH, making it easy to work on your projects or manage your server.

That's it! You've successfully set up SSH key authentication and configured your Windows machine to connect to a remote Ubuntu server. This streamlined process will save you time and make remote development a breeze. Happy coding!

Previous Post
No Comment
Add Comment
comment url