This Docker image provides an Ubuntu 24.04 base with SSH server enabled. It allows you to easily create SSH-accessible containers via SSH keys or with a default username and password.
To get started, clone the GitHub repository containing the Dockerfile and scripts:
git clone https://github.com/aoudiamoncef/ubuntu-sshd
cd ubuntu-sshdBuild the Docker image from within the cloned repository directory:
docker build -t my-ubuntu-sshd:latest .To run a container based on the image, use the following command:
docker run -d \
-p host-port:22 \
-e SSH_USERNAME=myuser \
-e SSH_PASSWORD=mysecretpassword \
-e AUTHORIZED_KEYS="$(cat path/to/authorized_keys_file)" \
-e SSHD_CONFIG_ADDITIONAL="your_additional_config" \
-e SSHD_CONFIG_FILE="/path/to/your/sshd_config_file" \
my-ubuntu-sshd:latest-druns the container in detached mode.-p host-port:22maps a host port to port 22 in the container. Replacehost-portwith your desired port.-e SSH_USERNAME=myusersets the SSH username in the container. Replacemyuserwith your desired username.-e SSH_PASSWORD=mysecretpasswordsets the SSH user's password in the container. This environment variable is required. Replacemysecretpasswordwith your desired password.-e AUTHORIZED_KEYS="$(cat path/to/authorized_keys_file)"sets authorized SSH keys in the container. Replacepath/to/authorized_keys_filewith the path to your authorized_keys file.-e SSHD_CONFIG_ADDITIONAL="your_additional_config"allows you to pass additional SSHD configuration. Replaceyour_additional_configwith your desired configuration.-e SSHD_CONFIG_FILE="/path/to/your/sshd_config_file"allows you to specify a file containing additional SSHD configuration. Replace/path/to/your/sshd_config_filewith the path to your configuration file.my-ubuntu-sshd:latestshould be replaced with your Docker image's name and tag.
Once the container is running, you can SSH into it using the following command:
ssh -p host-port myuser@localhosthost-portshould match the port you specified when running the container.- Use the provided password or SSH key for authentication, depending on your configuration.
- If the
AUTHORIZED_KEYSenvironment variable is empty when starting the container, it will still launch the SSH server, but no authorized keys will be configured. You have to mount your own authorized keys file or manually configure the keys in the container. - If
AUTHORIZED_KEYSis provided, password authentication will be disabled for enhanced security.
This Docker image is provided under the MIT License.