Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Windows 10 / Configure Remote SSH Connections in Visual Studio Code

March 15, 2024 LinuxWindows 10Windows 11

Configure Remote SSH Connections in Visual Studio Code

Visual Studio Code is a very feature-rich and versatile text editor that can benefit both developers and system administrators. You can use VS Code to edit your PowerShell scripts, configuration files, and run console commands. The Remote SSH extension allows you to connect to remote computers via SSH and edit files, scripts, configurations, or execute commands on remote Windows or Linux hosts directly from VS Code installed on your computer.

Here’s how to configure a Visual Studio Code SSH client to connect to remote hosts.

Run VS Code and go to Extensions ( Ctrl + Shift + X ). Now find and install the Remote SSH extension.

vs code install remote ssh extension

This automatically installs the following Remote SSH add-ons: Editing Configuration Files and Remote Explorer (Extension Pack tab).

Select Remote Explorer in the left panel of VSCode to create a new SSH connection. The connection wizard will prompt you to enter:

  • SSH connection string: [email protected]
  • the path to the configuration file containing the settings for this connection (by default, it’s C:\Users\%username%\.ssh\config ).
You can also create a new connection by pressing CTRL + SHIFT + P and selecting Remote-SSH: Connect to Host.

Visual Studio code - connect to remote ssh host

Once this is done, you can now connect to the remote host via SSH. Select the host from the list and click Connect.

The first time you connect, VSCode prompts you for the platform type on the remote SSH host (Linux/Windows/macOS) and the connection password:

select ssh platform

Once connected to the remote SSH host, you can edit any text files directly from the VSCode editor and execute shell commands as if you were connected via an SSH client (click Terminal -> New Terminal to open a console prompt).

Edit config file on remote Linux host from VSCode

If you try to save a file in VSCode that cannot be edited by a non-root user (without sudo), you will get the following error::

Failed to save 'sshd_config': Unable to write file 'vscode-remote://ssh-remote+192.168.79.128/etc/ssh/sshd_config' (NoPermissions (FileSystemError): Error: EACCES: permission denied, open '/etc/ssh/sshd_config').

(NoPermissions (FileSystemError): Error: EACCES: permission denied

One solution to this problem is to use the VSCode extension Save as Root in Remote – SSH. Once this extension is installed, you can save the file in sudo mode using the Save as Root command.

Both password and SSH key-based authentication are supported in Remote SSH.

Let’s try to configure SSH key-based authentication on a remote Windows host:

  1. Generate an SSH key pair on the client: ssh-keygen -t ed25519
    In this example, Windows 10 with the built-in SSH client is used.
  2. Copy the public key file C:\Users\%username%\.ssh\id_ed25519 into the file C:\Users\user1\.ssh\authorized_keys on your remote host (here, user1 is the user name you will connect with);
  3. Check that the following option is enabled in the OpenSSH server configuration file on Windows:
    PubkeyAuthentication yes
  4. Now open the file C:\Users\%username%\.ssh\config which contains the VSCode connection settings for SSH hosts. Find the host and add the IdentityFile parameter with the path to your private key file:
Host 192.168.31.4
  HostName 192.168.31.4
  User root
  IdentityFile "C:\Users\user1\.ssh\id_ed25519"

VScode SSH key-based auth

A quick way to open the config file is to press F1 -> Remote-SSH: Open SSH Configuration File.

remote ssh config file

Now the connection to the SSH host will be done with key-based authentication (no password required).

You can use the LocalForward directive to configure SSH tunnels and port forwarding. Or you might want to use the ForwardAgent and ProxyJump directives instead:

Host PublicJumpServer1
  HostName public.woshub.com
  User user1
  ForwardAgent yes

Host PrivateServer1
  HostName private.contoso.com
  User user1
  ProxyJump PublicJumpServer1
You can also connect to and develop in MS SQL Server with VS Code.
0 comment
3
Facebook Twitter Google + Pinterest
previous post
Configuring Password Policy in Microsoft Entra ID
next post
How to Fix ‘An Operating System Wasn’t Found’ Error on Windows

Related Reading

Unable to Map Drive: An extended error has...

May 13, 2025

Map a Network Drive over SSH (SSHFS) in...

May 13, 2025

How to Cancel Windows Update Pending Restart Loop

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Change BIOS from Legacy to UEFI without Reinstalling...

April 21, 2025

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Fixing ‘The Network Path Was Not Found’ 0x80070035 Error Code on Windows
  • Recovering Files from BitLocker Encrypted Drive
  • Installing an Open Source KMS Server (Vlmcsd) on Linux
  • How to Access VMFS Datastore from Linux, Windows, or ESXi
  • Install Any OS from ISO Image over Network with iVentoy
  • Using iPerf to Test Network Speed and Bandwidth
  • Moving WSL to Another Drive in Windows
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top