When you're running VS Code Remote SSH and loose network connectivity over a long period of time and return to VS Code, the status on the bottom left show's "Disconnected from SSH: ". However, there doesn't seem to be a way to reconnect the session. I always have to revert to starting a new VS Code Remote SSH session. How can I reconnect?
-
There is a command "Remote-SSH: Connect Current Window to Host", but using that has no effect for me. – Zitrax Feb 16 '21 at 07:24
4 Answers
You can reload the window. It keeps unsaved changes even. Press F1 to search for commands, then search for:
Developer: Reload Window
Version of VSCode when trying this: 1.53.2.

- 1,703
- 1
- 12
- 17
-
1
-
2@Danny When I do `CTRL+SHIFT+P` and type `reload window` I see that for me it is set to `CTRL+R`. If it is not set for you, you can set it in the keyboard shortcuts (`CTRL+K, CTRL+S` sequence) – lucidbrot Mar 15 '21 at 09:40
-
It work for me, it even keep the same workspace open after reloading. Thanks man! – Koen Jun 11 '21 at 16:05
-
reloading the window does not really work after a long period of time. what is the purpose of connecting to the same session? keep some process that is running alive? I think that using Tmux can help for that purpose – Rachel Shalom Dec 14 '21 at 08:13
-
unfortunately did not work for me, window is stall saving. If not saving remorely, window hangs with `Saving working copies`. – Alleo Jun 02 '22 at 18:00
EDIT: This does NOT work to reestablish the connection. It only helps to keep it alive. Thanks for the comments. I misinterpreted the question while looking for something similar for myself.
I'll leave the answer just in case it helps someone else.
You need to set a custom ssh file and add parameters to keep the connection to your host alive :
Host SomeRemoteHost
HostName MyRemoteHostName
User MyUsername
ServerAliveInterval 60
ServerAliveCountMax 30
Go to the SSH extension settings and set the new custom ssh config file path. This won't work if your machine goes into sleep mode, but it will keep the connection alive in the background while you work on other things.
PS: Make sure your ssh settings are correct for the host or you won't be able to log in.

- 2,526
- 22
- 26
-
4Keeping the connection alive longer might be nice when network connectivity is not interrupted, but the question was how to reconnect after a lengthy outage – ShadSterling Jan 20 '21 at 00:40
-
You are correct. My bad. I edited the answer to reflect it is wrong. It does not help to the original question at all. I don't know if there is any way to reconnect automatically. – Emilio Feb 16 '21 at 17:57
-
In line with @PaulOmta answer, the easiest way is now adding this Reload button extension! It adds a Reload button to your status bar on the bottom right.
I found that ⌘-R shortcut didn't work on mine (maybe because I have other keybinders on)
VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=natqe.reload

- 4,870
- 3
- 42
- 60
It seems that there is something that drops your idle connection. As I know SSH doesn't have any configuration for dropping an idle connection but firewalls has. there might be some sort of firewall or monitoring software or hardware device which drops your connection. if you are using Linux OS the following command might help you:
ssh -o "ServerAliveInterval 60" <SERVER_ADDRESS>
this command sends keep alive request to ssh every 60 seconds.

- 34
- 1
- 4
-
1Same issue is when waking computer after say hibernation - no way to re-connect – PunchyRascal Apr 01 '20 at 09:57