-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
614f9b6
commit 3a04d1f
Showing
4 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.github/ | ||
LICENCE | ||
readme.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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). |