By default, Coder enables SSH access for all users. Coder assigns each user a private key that they can use to access their workspaces.
Part of the standard Coder workspace asset bundle is a lightweight SSH server mounted onto the workspace agent; the lightweight SSH server is a backup used when Coder can't find a server available on port 22. This allows slimmer images to remain accessible via SSH without the need for additional image dependencies.
The built-in SSH server is limited and does not implement advanced functionality
like X11 forwarding or
sshd_config specifications. If SSH is the primary mode
of access to Coder for your users, or if you would like to take advantage of a
login shell, consider running an entire OpenSSH server with
your image instead.
To do so, add the following to your Dockerfile:
RUN apt-get update && apt-get install -y \
# Start OpenSSH with systemd
RUN systemctl enable ssh
# recommended: remove the system-wide environment override
RUN rm /etc/environment
# recommended: adjust OpenSSH config
RUN echo "PermitUserEnvironment yes" >> /etc/ssh/sshd_config && \
echo "X11Forwarding yes" >> /etc/ssh/sshd_config && \
echo "X11UseLocalhost no" >> /etc/ssh/sshd_config
Then, make sure that you're creating your workspaces with the CVM option enabled.
If Coder detects a running TCP server on port 22, it will forward incoming SSH traffic to this server. This means that workspaces should not run a TCP server on port 22 unless it can adequately handle incoming SSH traffic.
At startup, Coder injects the user's SSH key into
your workspace to facilitate authentication with OpenSSH. For the best
experience, add the following to your
/etc/ssh/sshd_config file inside your
X11 forwarding will fail with
X11 forwarding request failed on channel 0if
xauthis not installed.
OpenSSH handles environment variables differently than most container processes.
Environment variable overrides for OpenSSH sessions are set by
/etc/environment. Note that these values will
override those specified in the Dockerfile
At workspace startup, Coder injects the image defined environment variables into
~/.ssh/environment, as well as a set of Coder-defined defaults.
The following snippet shows an example of what this file may look like for a new workspace.
# --------- START CODER ENVIRONMENT VARIABLES ----------
# The following has been auto-generated at workspace startup
# You should not hand-edit this section unless you are deleting it.
# ----------------- END CODER -----------------------
If you would like to disable SSH access:
- Log into the Coder UI with a site manager account, and go to Manage > Providers.
- Select the workspace provider where you want to disable SSH. Click on the vertical ellipses to its right and select edit.
- Scroll down to the Features section and toggle External Connect to off.
Repeat these steps for each workspace provider where you want to disable SSH connections.