This repository contains a Dockerized simple SSH server setup using Alpine Linux. The server is configured to generate new SSH host keys, ensure the SSH user has the necessary directories, and start the SSH server.
.github/workflows/
: Contains GitHub Actions workflows.build.yaml
: Workflow for building and pushing the Docker image.
Dockerfile
: Dockerfile to build the SSH server image.entrypoint.sh
: Entrypoint script to set up and start the SSH server.sshd_config
: Configuration file for the SSH server.README.md
: This file.
The Docker image is built using the Dockerfile
and includes the following steps:
- Uses Alpine Linux as the base image.
- Adds the
sshd_config
andentrypoint.sh
files to the image. - Installs the
openssh-server
package. - Creates necessary directories and user.
- Sets permissions and ownership.
- Exposes port
2222
for SSH connections. - Sets the entrypoint to the
entrypoint.sh
script.
The entrypoint.sh
script performs the following actions:
- Generates new SSH host keys.
- Ensures the SSH user has a
.ssh
directory. - Adds any keys found in the
/workspace/keys
directory to the user's authorized keys. - Starts the SSH server.
The sshd_config
file configures the SSH server with the following settings:
- Listens on port
2222
. - Uses host keys located in
/workspace/etc/ssh/
. - Disables root login and password authentication.
- Enables public key authentication.
- Configures various other SSH settings.
In order to connect, you will need to mount a copy of your public key into /workspace/keys/
. This will then be added to the authorized_keys
file for the ssh-user
account.
The GitHub Actions workflow defined in .github/workflows/build.yaml
automates the building and pushing of the Docker image to GitHub Container Registry. It supports multiple platforms and runs on a schedule, on push, and on pull request events.
To run this container, you can use the following to pull from our official GitHub Packages repo:
docker pull ghcr.io/buildsociety/ssh:latest
docker run -p 2222:2222 -v /path/to/public/key.pub:/workspace/keys/key.pub ghcr.io/buildsociety/ssh:latest