Adds a SSH server into a container so that you can use an external terminal, sftp, or SSHFS to interact with it.
"features": {
"ghcr.io/devcontainers/features/sshd:1": {}
}
Options Id | Description | Type | Default Value |
---|---|---|---|
version | Currently unused. | string | latest |
While the some services automates SSH setup (e.g., when using the GitHub CLI for GitHub Codespaces), this may not be the case for other tools and services. Follow these directions to connect to the dev container from these other tools:
-
Connect to your dev container using a desktop tool or CLI that supports the dev container spec (e.g., VS Code client).
-
The first time you've started the container, you will want to set a password for your user. If running as a user other than root, and you have
sudo
installed:sudo passwd $(whoami)
Or if you are running as root:
passwd
-
Forward the SSH port (
2222
by default) to your local machine using either theforwardPorts
property indevcontainer.json
or the user interface in your tool (e.g., you can press F1 or Ctrl/Cmd+Shift+P and select Ports: Focus on Ports View in VS Code to bring it into focus). -
Use a local terminal (or other tool) to connect to it using the command and password from step 2. e.g.
ssh -p 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null vscode@localhost
...where
vscode
above is the user you are running as in the container and2222
after-p
is the local address port from step 2.The “-o” arguments are optional, but will prevent you from getting warnings or errors about known hosts when you do this from multiple containers/codespaces.
-
Next time you connect to your container, just repeat steps 3 and 4 and use the same password you set in step 2.
SSHFS allows you to mount a remote filesystem to your local machine with nothing but a SSH connection. Here's how to use it with a dev container.
-
Follow the steps in the previous section to ensure you can connect to the dev container using the normal
ssh
client. -
Install a SSHFS client.
-
Mount the remote filesystem.
-
macOS / Linux: Use the
sshfs
command to mount the remote filesystem. The arguments are similar to the normalssh
command but with a few additions. For example:mkdir -p ~/sshfs/devcontainer sshfs "vscode@localhost:/workspaces" "$HOME/sshfs/devcontainer" -p 2222 -o follow_symlinks -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o GlobalKnownHostsFile=/dev/null -C
...where
vscode
above is the user you are running as in the container (e.g.codespace
,vscode
,node
, orroot
) and2222
after the-p
is the same local port you used in thessh
command in step 1. -
Windows: Press Window+R and enter the following in the "Open" field in the Run dialog:
\\sshfs.r\vscode@localhost!2222\workspaces
...where
vscode
above is the user you are running as in the container and2222
after the!
is the same local port you used in thessh
command in the previous section.
-
-
Your dev container's filesystem should now be available in the
~/sshfs/devcontainer
folder on macOS or Linux or in a new explorer window on Windows.
This Feature should work on recent versions of Debian/Ubuntu-based distributions with the apt
package manager installed.
bash
is required to execute the install.sh
script.
Note: This file was auto-generated from the devcontainer-feature.json. Add additional notes to a NOTES.md
.