peng zhang
peng zhang

Reputation: 831

why ssh connection timed out in vscode?

I installed git instead of openssl to use Remote-SSH in VSCode.However,after I completed the config document and tried to connect to the remote host.I failed. The error info is showed in the below pic.error info

error info:

[11:27:12.631] [email protected]
[11:27:12.632] win32 x64
[11:27:12.656] SSH Resolver called for "ssh-remote+23321", attempt 1
[11:27:12.659] SSH Resolver called for host: 23321
[11:27:12.659] Setting up SSH remote "23321"
[11:27:12.790] Using commit id "26076a4de974ead31f97692a0d32f90d735645c0" and quality "stable" for server
[11:27:12.798] Testing ssh with ssh -V
[11:27:13.099] ssh exited with code: 0
[11:27:13.100] Got stderr from ssh: OpenSSH_8.1p1, OpenSSL 1.1.1d  10 Sep 2019
[11:27:13.128] Running script with connection command: ssh -T -D 49485 23321 bash
[11:27:13.132] Install and start server if needed
[11:27:13.151] Terminal shell path: C:\Windows\System32\cmd.exe
[11:27:30.151] Resolver error: Connecting with SSH timed out
[11:27:30.178] ------

Upvotes: 83

Views: 152248

Answers (21)

Patrick Michaelsen
Patrick Michaelsen

Reputation: 1045

For me, this is what finally fixed it. I set the setting remote.SSH.remoteServerListenOnSocket to true:

{
  //...
  "remote.SSH.remoteServerListenOnSocket": true
}

then killed the VS Code server on the remote and retried my connection.

Upvotes: 1

Felix Neto
Felix Neto

Reputation: 1

I've added a solution to my timeout issue when connecting to my server via VSCode.

After trying several methods, I successfully resolved the problem by clearing only the 'servers' folder within the '.vscode-server' user configuration.

rm -rf /home/$USER/.vscode-server/cli/servers/*

Upvotes: 0

Thomas Fritz
Thomas Fritz

Reputation: 340

Also make sure that your bashrc (or equivalent in other shells) doesn't contain any blocking program executions.

Because I'm a fish user but my server OS heavily depends on bash being the default shell, I had a call to fish in my bashrc so it would automatically open fish whenever I logged into server. Specifically, my ~/.bashrc file looked like this:

fish

Whenever VSCode tried to log into that server via ssh, it executed this bashrc, opened an interactive fish session, waited for that to close (which never happened) before timing out after 15 seconds.

My solution to this problem was to add an interactive shell check to my bashrc so it would only run fish in interactive ssh sessions, but not when I tried to connect to the server through VSCode's SSH extension:

if [[ $- == *i* ]] then    # interactive session check
    fish
fi

Upvotes: 0

floatingeye
floatingeye

Reputation: 113

Tried a few different methods in this thread, but none worked for me.

The root cause of my issue was actually due to some hanging nfs mounts located in the ~/.vscode-server directory. These were caused by an extension I had installed. After uninstalling the extension on the remote server, I was able to delete the files in question and there was no longer an issue with lagginess, which in turn caused timeouts to occur. So if you are experiencing the same issue, check the ~/.vscode-server/bin directory (where extensions are installed) and see if there are any hanging nfs files. If there are, try my method.

Thank you.

Upvotes: 0

Richard Muvirimi
Richard Muvirimi

Reputation: 844

In my case trying from a Mac machine and the server being Linux, I had to add the entry

    "remote.SSH.remotePlatform": {
        "127.0.0.1": "linux"
    },

where 127.0.0.1 is the IP address of your remote server

I had tried increasing the timeout to no avail, including restarting vs code

Upvotes: 0

dalewb
dalewb

Reputation: 21

Fixed it in settings (I'm using the Remote SSH extension)

File -> Preferences -> Settings -> Extensions -> Remote-SSH

At the bottom, uncheck Remote.SSH Use Local Server

Upvotes: 1

Kairosclerosis
Kairosclerosis

Reputation: 1

My issue was similar to above posts, I just opened command palette (Ctrl+shift+p), searched Remote-SSH settings, and changed the timeout from 15 seconds to something longer

Upvotes: 0

Aaron Williams
Aaron Williams

Reputation: 643

Been struggling with this for a while now... i keep trying to resolve it but unsuccessfully, although i do have a workaround.

My situation is that I regularly run 3 projects together in separate VSCode windows, and one particular project always has this issue lately (especially after a VSCode release restart), even though they are all on the same remote server within my user directory.

The only way i can resolve it (the workaround) is to:

  • close VSCode
  • go to my user dir in Windows \AppData\Roaming\Code\User\workspaceStorage
  • delete the folders (or just the latest timestamp one if you know this is definitely the one for the project with the issue)

Note: i run Windows locally and RHEL remotely.

Upvotes: 0

Karsten Becker
Karsten Becker

Reputation: 510

For me the issue was that on the server I wanted to connect to, the /etc/ssh/sshd_config contained:

AllowTcpForwarding no

Changing that to

AllowTcpForwarding yes

Did solve my ssh connection timeout issue.

Upvotes: 1

Youcef4k
Youcef4k

Reputation: 396

Well before trying all of the above methods, try the nice old method: restart your PC.

I tried all the suggested methods and nothing worked for me, then I just turned off and then on and everything is magically working!

Upvotes: 2

Jacob Andersson
Jacob Andersson

Reputation: 71

I had a case of this. I my client (local computer) is a Mac, and I was connecting to Linux host. I just went to the setting "Remote Platform" under Remote.SSH settings, and explicitly told it that I am connecting to a Linux remote. After this, it started to work.

Upvotes: 7

Shivam Papat
Shivam Papat

Reputation: 531

The issue with me was timeout at first. I tried increasing the timeout in settings but then later found the issue was with "tar".

The vscode-server.tar.gz (probably a little change in the file name) was not able to install due to tar not being present in my host. So I installed tar in the host as "yum install tar" And then tried reconnecting to the server and it worked

Upvotes: 0

Yan
Yan

Reputation: 78

This might be a very foolish solution but it actually works for me, so I will write it down in case any other people get into the same problem. I made modifications to the config file for SSH, then all the trials for connection ran into the error of 'Connecting SSH timed out'. I tried many possible solutions but none of them solved my problem.

Then I just closed the VScode and restarted it. Then everything works.

Upvotes: 3

Sobia Rind
Sobia Rind

Reputation: 71

I had same issue, my problem was solved after changing settings in the json file:

  1. I removed "terminal.integrated.inheritEnv": false inside ~/.config/Code/User/setting.json
  2. I added "remote.SSH.useLocalServer": true inside ~/.config/Code/User/setting.json

It worked for me after so many different trials

Upvotes: 5

Barkaas
Barkaas

Reputation: 46

I had this issue because of version missmatch of client and server. After updating both to the same version, it worked for me.

Upvotes: 0

smsarwar
smsarwar

Reputation: 371

You can try the following approaches:

  1. ssh to your remote server. Then run the following commands to clean data folder and bin folder under .vscode-server folder on the server:
  • cd ~/.vscode-server
  • rm data/* -rf
  • rm bin/* -rf
  1. If step 1 does not work, ssh to your remote server and delete the entire .vscode-server folder with the following command:

    rm -rf ~/.vscode-server

    Please note that this will also remove the extensions that you installed on the server.

  2. Downgrade the version of the remote-SSH extension in vscode. Look up the extension in the vscode interface, right click on that, and you will find the option "Install Another Version ...". Install the previous version of the current one. If it does not work keep downgrading the version.

Upvotes: 11

franman726
franman726

Reputation: 121

key F1 Remote-SSH: Settings Connect Timeout: from 15 seconds to 60 seconds solve my connection issue

Upvotes: 11

Yonti
Yonti

Reputation: 1479

In my case, the problem was caused by a too long authentication process on the server-side.

Solved it by extending the Connect Timeout from 15 to 30 seconds.

Instructions:

  1. open your vscode Command Palette (via keyboard shortcut or from the View menu).
  2. search for the Remote-SSH: Settings.
  3. scroll till you find the Connect Timeout.
  4. change it to a longer duration than 15 secs.

Upvotes: 107

Snehal Parmar
Snehal Parmar

Reputation: 5823

I had the same problem but the above solutions didn't work with my setup, but the following setting did work:

"remote.SSH.useLocalServer": false

I got this solution from github reported issues and fix

Upvotes: 112

jaques-sam
jaques-sam

Reputation: 2795

I found the solution here in this thread from user oreilm49: https://github.com/microsoft/vscode-remote-release/issues/1137

in vscode settings : search conpty and uncheck it

Upvotes: 5

EequalsMC2
EequalsMC2

Reputation: 71

I had the same problem before, I solved this by deleting "terminal.integrated.inheritEnv": false inside ~/.config/Code/User/setting.json

Upvotes: 7

Related Questions