How to connect VSCode remote development to a Fly machine?

I am trying to use VSCode remote development via SSH to manage a Fly machine using VSCode, the use cases are

  • Use Fly as rentable GPU machine
  • Run scripts inside Fly to get more compute and faster internet connection

The steps I successfully followed are

  1. Connect my machine to the Fly Wireguard network
  2. Now I can run ssh root@app-name.interal successfully
  3. I tried connecting to the machine with VSCode Remote SSH: Connect to Host...
  4. From the logs I saw some commands are missing like curl and ps, install them with apt-get install -y procps curl
  5. Now I still get the error Failed to set up socket for dynamic port forward to remote port 42193: Socket closed. TCP port forwarding may be disabled, or the remote server may have crashed. See the VS Code Server log above for details.

The full logs:

12:13:36.233] Remote server is listening on port 37957
[12:13:36.233] Parsed server configuration: {"serverConfiguration":{"remoteListeningOn":{"port":37957},"osReleaseId":"debian","arch":"x86_64","sshAuthSock":"","display":"","tmpDir":"/tmp","platform":"linux","execServerToken":"xxx"},"serverStartTime":69,"installUnpackCode":""}
[12:13:36.234] Persisting server connection details to /Users/morse/Library/Application Support/Cursor/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-af572e01-0.113.1-es/data.json
[12:13:36.237] Starting forwarding server. local port 51229 -> socksPort 51226 -> remotePort 37957
[12:13:36.238] Forwarding server listening on port 51229
[12:13:36.238] Waiting for ssh tunnel to be ready
[12:13:36.238] Tunneled port 37957 to local port 51229
[12:13:36.239] Resolved "ssh-remote+minecord-website.internal" to "port 51229"
[12:13:36.245] Initizing new exec server for ssh-remote+minecord-website.internal
[12:13:36.245] Resolving exec server at port 51229
[12:13:36.259] [Forwarding server port 51229] Got connection 0
[12:13:36.259] [Forwarding server port 51229] Got connection 1
[12:13:36.385] stderr> Read from remote host minecord-website.internal: Connection reset by peer
[12:13:36.386] stderr> client_loop: send disconnect: Broken pipe
[12:13:36.387] Failed to set up socket for dynamic port forward to remote port 37957: Socket closed. TCP port forwarding may be disabled, or the remote server may have crashed. See the VS Code Server log above for details.
[12:13:36.387] Failed to set up socket for dynamic port forward to remote port 37957: Socket closed. TCP port forwarding may be disabled, or the remote server may have crashed. See the VS Code Server log above for details.

Hi… I may be misunderstanding what you attempted, but Fly.io’s built-in SSH server (hallpass) is intentionally rather minimal and doesn’t support port forwarding (at least not last I heard).

What you can do instead is use @rubys’s trick of installing OpenSSH’s server in parallel with the built-in one:

https://fly.io/docs/blueprints/opensshd/

Then you can just ask VSCode to contact port 2222 instead of port 22.

Hope this helps!

1 Like

I took a look at the server logs and it shows ERROR unexpected channel type type=direct-tcpip

I think the problem is that Fly ssh is missing some forwarding implementation.

It would be awesome if Fly added support for this workflow.

You could even add a command fly vscode to make opening an instance of VSCode super easy for everyone that doesn’t know how Wireguard works, the command would

  • Setup a Wireguard connection like fly console does
  • Proxies the ssh connection to a port on localhost
  • Run the command code --remote ssh-remote+localhost:forwarded-port /cwd to open VSCode on that machine

There are so many use cases for this:

  • Debug a machine issues using VSCode terminal, file explorer, search, etc
  • Quickly connect to a powerful machine using the IDE you already know
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.