Skip to main content
Version: 6.x (Latest)

Inject An SSH Server Into Dev Container

DevSpace allows you to start an SSH server in the target container, to easily connect to your development environment. This has the following advantages:

  • Since IDE's have a great remote SSH integration you can use that directly for your Kubernetes containers
  • Use all SSH features and tools such as scp or terminal with your development container

DevSpace will make sure that ssh is properly configured locally and automatically add an entry to your ~/.ssh/config as well as create an appropriate ssh key pair in ~/.devspace/ssh/id_devspace_rsa to establish a secure connection with the remote container. You can then connect to the container with ssh <dev-config-name>.<devspace-name>.devspace, where <dev-config-name> denotes the name of the dev config and <devspace-name> the name of the devspace.yaml file.

For example, to start ssh for an ubuntu container:

name: my-devspace-project

deployments:
my-deployment:
helm:
values:
containers:
- image: ubuntu

dev:
my-dev:
imageSelector: ubuntu
ssh: {}

After starting devspace dev, you will be able to connect to the ubuntu container with ssh my-dev.my-devspace-project.devspace.

How does it work?

DevSpace will inject a small helper binary into the running container that contains an SSH server. Then DevSpace will port-forward a random local port to the remote SSH port and configure the local ~/.ssh/config accordingly.

Config Reference

ssh required

SSH allows you to create an SSH tunnel to this container

enabled required boolean false

Enabled can be used to enable the ssh server within the container. By default, DevSpace will generate the required keys and create an entry in your ~/.ssh/config for this container that can be used via ssh dev-config-name.dev-project-name.devspace

localHostname required string

LocalHostname is the local ssh host to write to the ~/.ssh/config

localPort required integer

LocalPort is the local port to forward from, if empty will be random

remoteAddress required string

RemoteAddress is the address to listen to inside the container

useInclude required boolean false

UseInclude tells DevSpace to use a the file ~/.ssh/devspace_config for its ssh entries. DevSpace will also create an import for its own entries inside ~/.ssh/config, this is a cleaner way, but unfortunately not all SSH clients support this.