Fixing VS Code SSH Connection Failures

by | Mar 2, 2024 | Software Development | 0 comments

I use the Firewalla Purple Firewall/Router. I am unsure if that has anything to do with this issue I often face, but I figured I’d mention it. Also, I’d like to mention that the Firewilla Purple is a fantastic device that I highly recommend. I also use VS Code as my primary text editing application on Mac OS. I was a long-time Sublime user, and just like when I resisted the move from Perl to Python – when I finally made the switch, I was glad I did.

VS Code has a really cool SSH integration that allows you to edit files on a remote server as long as that server provides SSH access.

VS Code Remote SSH: Connect to HostFor some reason (feel free to tell me in the comments), VS Code cannot make successful connections to a remote Mac OS server without being forced to do so over IPv4.

The Problem

As you can see in the image below, VS Code is unable to connect.

VS Code Unable to SSH Connect
Taking a look below at the error in VS Code’s Output pane, it looks like SSH has timed out. I have replaced my actual servername with “myservername“.

[08:12:57.726] > local-server-1> Running ssh connection command: ssh -v -T -D 64542 -o ConnectTimeout=15 myservername
[08:12:57.726] > local-server-1> Spawned ssh, pid=45060
[08:12:57.743] stderr> OpenSSH_9.4p1, LibreSSL 3.3.6
[08:13:14.641] Terminating local server
[08:13:14.650] Resolver error: Error: Connecting with SSH timed out
at g.Timeout (/Users/seth/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:460371)
at Timeout._onTimeout (/Users/seth/.vscode/extensions/ms-vscode-remote.remote-ssh-0.108.0/out/extension.js:2:525786)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7)
[08:13:14.660] ------

The Solution

After a bit of googleing, and trying different things, I found something that worked. Again, not totally sure why this makes a difference, and if you know, please do tell me in the comments, but, the solution was to limit the SSH connection, via the ~/.ssh/config file, to only use IPv4.

A copy of my ~/.ssh/config file is below. Again, I have replaced my actual server name with “myservername“.

Host myservername
  HostName myservername
  AddressFamily inet
After adding the AddressFamily inet line to the Host entry in the ~/.ssh/config file VS Code successfully makes the SSH connection to the server and can remotly edit configuration files.


Submit a Comment

Your email address will not be published. Required fields are marked *

Seth Lippman

Striving to make the world a better place through technology.

Use Docker to Provision Multiple WordPress Websites on a Single Server

This post will demonstrate using docker to provision two stand-alone SSL-secured WordPress websites with different root domains on a single server.  Both websites are backed by individual Oracle MySQL databases and phpMyAdmin interfaces.[pac_divi_table_of_contents...

Snowfall over Gorgon City

This was the second time Stacia and I have seen Gorgon City, and the second time we've seen them at Red Rocks. Immediatly after our first Gorgon City show, which featured an appearnce by Drama, we knew we'd come back any time Gorgon City played at Red Rocks.  What we...

Breakfast, Breakbeats, Birthdays, and Tim Burton

I was reading through online posts celebrating my partner Stacia's birthday when a social media platform notified me that it was also my friend Simon's birthday. Simon is someone I used to go to Drum & Bass shows with in London whilst attending university there in...