Will it be possible to create an SSH tunnel to a Codespaces instance?

For example, to connect via a local terminal, or to use SSHFS for easy access to project files.

Hey! This is something we’ve discussed adding support for, and it would be extremely helpful to learn more about your use case. Are you primarily interested in this so that you could use another local desktop app against the files in the Codespace? (e.g. an image editor)

Yes, for some file types it can be very convenient to use local applications (e.g. Adobe Acrobat DC for browsing/reading PDF files, WinRAR for viewing/unzipping archives, and so on). Quite often you need to quickly move files from the development environment to local storage, and vice versa (Visual Studio Code supports drag-n-drop in the latter case, but the former, as far as I know, is impossible without SSH). Finally, when I was writing this question, the main problem was the need to open HTML files in a browser, which is very easy to do if you use SSHFS.

Generally, the problems described can be partially or completely bypassed by using extensions inside the editor, however, these are crutches, and it would be better to have a more natural way of interaction.

Got it, yeah that makes total sense. Thanks for providing that extra detail! This is something we definitely want to enable, but we don’t have any concrete timelines to share yet.

As you said, the current workaround is to leverage an extension that augments the editor for the specific file type you want to manage. For viewing HTML files, you can checkout the Live Server extension and then forward the port that it starts up. Definitely not as smooth as it could be, but maybe enough to unblock you for now?

Well, I have a slightly different approach to developing in the cloud right now, so it’s no longer a problem.

You mean you’re no longer using Codespaces? Or that you worked around this limitation in a different way?

Yes, I don’t use it anymore. This problem is quite important for current projects, so for now, I keep Codespaces a bit on the sidelines.

See if this works for you:

  1. Create a codespace
  2. Connect to it using VS Code locally
  3. Next, open a terminal (Crtl+Shift+`) in VS Code and run the following:
    curl -sSL https://raw.githubusercontent.com/microsoft/vscode-dev-containers/master/script-library/sshd-debian.sh | sudo bash -s -- 2222 $(whoami) true random
    
  4. Take note of the password that was generated and the SSH command.
  5. Press F1 and select Codespaces: Forward Port
  6. Enter port 2222
  7. Your codespace now has a running SSH server in it. Use a local termal (or other tool) to connect to it using the command and password from step 3. e.g.
    ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null codespace@localhost
    

The “-o” arguments are optional, but will prevent you from getting warnings or errors about known hosts when you do this from multiple codespaces.

Next time you connect, you can spin up the SSH server again by running: /usr/local/share/sshd-init.sh in a terminal and using the same command / password.

EDIT: Note that there is a right-click “Download” option in addition to dragging into the explorer to copy from local, but the script above will let you use SSHFS for local tool access.

Fantastic! Worked like a charm. Thank you very much, Chuck.

1 Like

As a FYI - This script will soon be in the default image for Codespaces. Once that is there, you’ll can just run sudo passwd $(whoami) to set a password and then forward the SSH port. So it will soon be even easier.

UPDATE: This is now live. If you type docker image ls and see 0.17.0 or greater, a SSH server is there by default.