post

Fixing VSCode when it keeps dropping ssh connections

I really like VSCode, and I use the ssh plugin to edit code on remote machines, but recently the ssh connection has been dropping all of the time, even when I’m editing code on another machine that’s on the same local network.

I’ve updated both my OS and VSCode multiple times recently, so I thought some bug had slipped into one of the updates and that was causing a problem. I was somewhat correct. It seems that VSCode keeps a cache of data and code on the remote machine, and something in a VSCode update was trying to do something using the bits in the old cache data that was no longer supported.

To fix the problem I just removed the cache as follows:

  • Exit completely out of VSCode so that no VSCode processes are running. Force quit if you have to.
  • ssh to the remote machine(s) and delete the ~/.vscode-server directory with rm -Rf ~/.vscode-server/
  • If you get any “cannot remove [file]: Device or resource busy” errors then look for stuck processes:
    lsof | grep $HOME/.vscode-server | awk '{ print $2 }' | sort -u
    … then kill those processes, then trying removing the directory again.
  • Restart VSCode.

Once I did this all of my connection problems disappeared.

Hope you find this useful.

14 thoughts on “Fixing VSCode when it keeps dropping ssh connections

  1. Thank you very much! only your solution works!!! vscode-github should refer to your page for this problem!

  2. Hi, I don’t ssh into Ubuntu 22.10, but rdp into it. I get thrown out of Ubuntu (it seems to log me off as I have a login screen I can see.) I am not sure what is causing this, but it seems to me that VS Code (both stable and insiders) seems to be a common factor. I’ve tried your interesting fix, but sadly no joy. I hope I find a solution as this is becoming more than an annoyance.
    (Ubuntu 22.10 (desktop) on a HP Micrososrver Gen8 for those interested :)

    • No, this was a red herring (false alarm). It happened when VS Code wasn’t open. I may have possibly linked it to someone trying to hack into my server via ssh. I have now set that up to use ssl encryption cert.

  3. I’ve been trying to fix this issue since two days and finally your guidance saved another day. I’m extremely grateful sir. Thanks a million!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.