Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to reconnect to a disconnected VS Code Remote SSH connection?

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?

like image 457
smartexpert Avatar asked Mar 16 '20 22:03

smartexpert


People also ask

How does Visual Studio Code connect to SSH server?

In VS Code, select Remote-SSH: Connect to Host... from the Command Palette (F1, Ctrl+Shift+P) and use the same user@hostname as in step 1. If VS Code cannot automatically detect the type of server you are connecting to, you will be asked to select the type manually.

How add SSH key to VS Code?

Add SSH key to your VM#Select Use existing public key in the dropdown for SSH public key source so that you can use the public key you just generated. Take the public key and paste it into your VM setup, by copying the entire contents of the id_ed25519. pub in the SSH public key.


Video Answer


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

like image 89
Paul Omta Avatar answered Oct 06 '22 19:10

Paul Omta


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.

like image 44
Emilio Avatar answered Oct 06 '22 20:10

Emilio


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.

like image 1
iman rameshni Avatar answered Oct 06 '22 19:10

iman rameshni