diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ce6b2f9 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.github/ +LICENCE +readme.md \ No newline at end of file diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml new file mode 100644 index 0000000..df98e69 --- /dev/null +++ b/.github/workflows/ci_cd.yml @@ -0,0 +1,29 @@ +name: Docker Image Deployment + +on: + push: + branches: + - 'main' + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v5 + with: + push: true + tags: aoudiamoncef/ubuntu-sshd:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5ac3a6d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use an official Ubuntu base image +FROM ubuntu:22.04 + +# Set environment variables to avoid interactive prompts during installation +ENV DEBIAN_FRONTEND=noninteractive + +# Install OpenSSH server and clean up +RUN apt-get update \ + && apt-get install -y openssh-server \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + +# Generate SSH keys (you can replace them with your own) +RUN mkdir /var/run/sshd \ + && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin without-password/' /etc/ssh/sshd_config \ + && sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config \ + && ssh-keygen -A + +# Expose SSH port +EXPOSE 22 + +# Create authorized_keys file if AUTHORIZED_KEYS is not empty, then start SSH server +CMD /bin/sh -c "[ -n \"$AUTHORIZED_KEYS\" ] && mkdir -p /root/.ssh && echo \"$AUTHORIZED_KEYS\" > /root/.ssh/authorized_keys; /usr/sbin/sshd -D" diff --git a/README.md b/README.md index bac1587..07ccc72 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,46 @@ -# ubuntu-sshd -This project provides a way to create a Docker image based on an official Ubuntu Image with an SSH server (SSHD) enabled +# SSH-Enabled Ubuntu Docker Image + +This Docker image provides an Ubuntu 22.04 base with SSH server enabled. It allows you to easily create SSH-accessible containers via ssh keys. + +## Usage + +### Building the Docker Image + +1. Clone this repository or create a Dockerfile based on the provided instructions. + +2. Build the Docker image. You can specify the image name and tag as desired: + + ```bash + docker build -t aoudiamoncef/ubuntu-sshd:latest . + ``` + +### Running a Container + +To run a container based on the image, use the following command: + +```bash +docker run -d -p host-port:22 -e AUTHORIZED_KEYS="$(cat path/to/authorized_keys_file)" aoudiamoncef/ubuntu-sshd:latest +``` + +- `-d` runs the container in detached mode. +- `-p host-port:22` maps a host port to port 22 in the container. Replace `host-port` with your desired port. +- `-e AUTHORIZED_KEYS="$(cat path/to/authorized_keys_file)"` sets authorized SSH keys in the container. Replace `path/to/authorized_keys_file` with the path to your authorized_keys file. +- `aoudiamoncef/ubuntu-sshd:latest` should be replaced with your Docker image's name and tag. + +### SSH Access + +Once the container is running, you can SSH into it using the following command: + +```bash +ssh -p host-port root@localhost +``` + +- `host-port` should match the port you specified when running the container. + +### Note + +- If the `AUTHORIZED_KEYS` environment 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. + +## License + +This Docker image is provided under the [MIT License](LICENSE). \ No newline at end of file