0

So I've been using the VS Code Remote-SSH extension for around 2 years now, basically daily, and everything was working just fine.

Now in the last couple of weeks, I've not been able to connect to a remote server using VS Code which has a custom port number set (I can connect to it manually over SSH, so it's not the remote machine). I've tried multiple different ways of setting the ssh config, and none of them seem to be working, it still just defaults to port 22, even though I very clearly have a custom port set in my config.

This is the output I get when trying to open the remote server in ssh:

Install terminal quit with output: ssh: connect to host_name port 22: Connection refused
Received install output: ssh: connect to host_name port 22: Connection refused
Failed to parse remote port from server output

My config looks like this:

Host server_name
  HostName server_ip_address
  User username
  Port 1234

I've also tried using different configs like:

# this solved an issue previously where the extension wasn't using the specified username to connect on some test machines
Host username@server_name
  HostName server_ip_address
  User username
  Port 1234

and

# where <server_name> has the IP specified in my local 'hosts' file
Host server_name
  HostName server_name
  User username
  Port 1234

This exact config has been working reliably for the last 9 months or so since I've been managing the remote server, but like I said, it suddenly stopped connecting on the custom port, and I've spent hours trying to find a solution, or at least the problem, and I haven't come across anything that's worked, or even pointed me in the right direction. So any advice or redirection on this will be great.

starball
  • 20,030
  • 7
  • 43
  • 238
KyleDev
  • 11
  • 1
  • 5

2 Answers2

0

The configuration looks correct as in the documentation: https://code.visualstudio.com/docs/remote/ssh

This error message is likely related to the server. It may not be listening on the specified port, or there may be firewall restrictions or incorrect network settings.

To troubleshoot, you can:

  • Use a console SSH client or a GUI client like FileZilla or CyberDuck to connect to the server.

  • Check if the port is open using nmap.

    # nmap myserver -p 22
    Starting Nmap 7.93 ( https://nmap.org ) at 2023-05-04 13:55 EEST
    Nmap scan report for myserver (192.168.0.102)
    Host is up (0.043s latency).
    
    PORT   STATE SERVICE
    22/tcp open  ssh
    
    Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds```
    
Borislav Gizdov
  • 1,323
  • 12
  • 22
  • I tried checking the port on the remote host and it's up and running as expected. I can still connect to the host via command prompt, but not via VS Code, because of it trying to use port 22 instead of my configured custom port. I've also been having other issues with VS Code where it uses my windows username instead of the remote host username that I've configured as well. I haven't yet found any other mention of this issue online though – KyleDev May 06 '23 at 22:08
  • Can you check that you don’t gave another config in ~/.ssh/ see https://dev.to/smac89/custom-ports-in-ssh-config-for-vscode-remote-ssh-505c – Borislav Gizdov May 07 '23 at 07:13
  • Okay I sort of figured it out. There isn't any duplicate config file, but there seems to have been another file that VSCode was using to read the hostname and address from. I'll post an answer for how I resolved it. – KyleDev May 08 '23 at 13:06
0

I eventually figured it out.

After some searching up after @Borislav Gizdov advised me to check for duplicates. I went searching on my machine and while I didn't find any duplicates, I did end up checking my Remote-SSH extension settings and found that I could specify a custom config path, which I did, and now it works as expected.

The strange thing to note is that VS Code displayed the correct config file path to me every time I went to edit the config file from within VS Code while debugging, which is very strange because it's the exact same path that I added in manually, and changes I made to that same file were reflected in VS Code, but my username and port numbers were being defaulted to other values.

KyleDev
  • 11
  • 1
  • 5