/docker-centos-sshd

A simple, dockerized, OpenSSH service built on top of the official CentOS Docker image.

Primary LanguageShell

CentOS SSHD

A simple OpenSSH Docker image built atop CentOS 7. Available on GitHub.

The root password is "root". SSH host keys (RSA, DSA, ECDSA, and ED25519) are autogenerated when the container is started, unless already present.

Also consider sickp/alpine-sshd for something smaller.

Tags

  • 7, latest (OpenSSH_6.6.1p1, OpenSSL 1.0.1e-fips 11 Feb 2013)

Basic usage

$ docker run -dP --name=sshd sickp/centos-sshd
7b7579858c25bf07b48d6442bf4d346a140b86d0405809af9efde14ba4377d2a

$ docker logs sshd
ssh-keygen: generating new host keys: RSA1 RSA DSA ECDSA ED25519
Server listening on 0.0.0.0 port 22.
Server listening on :: port 22.

$ docker port sshd
22/tcp -> 0.0.0.0:32768

$ ssh root@localhost -p 32768 # on Mac/Windows replace localhost with $(docker-machine ip default)
# The root password is "root".

Any additional arguments are passed to sshd. For example, to enable debug output:

$ docker run -dP --name=sshd sickp/centos-sshd -o LogLevel=DEBUG

Customize

This image doesn't attempt to be "the one" solution that suits everyone's needs. It's actually pretty useless in the real world. But it is easy to extend via your own Dockerfile. See the examples directory.

Change root password

Change the root password to something more fun, like "password" or "sunshine":

FROM sickp/centos-sshd:latest
RUN echo "root:sunshine" | chpasswd

Use authorized keys

Disable the root password completely, and use your SSH key instead:

FROM sickp/centos-sshd:latest
RUN usermod -p "!" root
COPY identity.pub /root/.ssh/authorized_keys

Create multiple users

Disable root and create individual user accounts:

FROM sickp/centos-sshd:latest
RUN \
  usermod -p "!" root && \
  useradd sickp && \
  mkdir ~sickp/.ssh && \
  curl -o ~sickp/.ssh/authorized_keys https://github.com/sickp.keys && \
  useradd afrojas && \
  mkdir ~afrojas/.ssh && \
  curl -o ~afrojas/.ssh/authorized_keys https://github.com/afrojas.keys

Embed SSH host keys

Embed SSH host keys directly in your private image, so you can treat your containers like cattle.

FROM sickp/centos-sshd:latest
RUN \
  usermod -p "!" root && \
  ssh-keygen -A && \
  useradd sickp && \
  mkdir ~sickp/.ssh && \
  curl -o ~sickp/.ssh/authorized_keys https://github.com/sickp.keys

History

  • 2016-01-28 - Rebuilt against latest CentOS 7 rolling image.
  • 2015-11-16 - Simplified entrypoint and host key generation. Reorganized.
  • 2015-11-11 - Allow passing of arguments to SSHD.
  • 2015-11-03 - Collapse layers, setuid ping, .dockerignore, more examples.
  • 2015-11-02 - Initial version.