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.
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.