diff --git a/Dockerfile b/Dockerfile index b7da2cc..7f0ed3b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,5 @@ FROM ubuntu:22.04 -# Update the system, install OpenSSH Server RUN apt-get update && apt-get upgrade -y && \ apt-get install -y openssh-server @@ -9,6 +8,8 @@ RUN echo "PermitRootLogin yes" >> /etc/ssh/ssh_config RUN mkdir /run/sshd RUN mkdir /root/.ssh +ENV PUBLIC_SSH_KEY "" + EXPOSE 22 -CMD ["/usr/sbin/sshd", "-D"] +CMD [ "/bin/sh", "-c", "echo $PUBLIC_SSH_KEY > /root/.ssh/authorized_keys && chown root:root /root/.ssh/authorized_keys && chmod 644 /root/.ssh/authorized_keys && exec /usr/sbin/sshd -D" ] diff --git a/README.md b/README.md index 6c2c208..efb50c4 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,15 @@ -# ubuntu-sshd-image +# ubuntu-sshd-image Ubuntu image with sshd configured for use in testing # Usage -Create a `authorized_keys` file in which you put your public key. Make sure the file is owned by -root and has the permission `644`. +Pass in your public key as an environment variable `PUBLIC_SSH_KEY`. ```sh -cat ~/.ssh/id_ed25519.pub > authorized_keys -chown root:root authorized_keys -chmod 644 authorized_keys - docker run \ - --mount type=bind,src=$(pwd)/authorized_keys,dst=/root/.ssh/authorized_keys \ + -e PUBLIC_SSH_KEY="ssh-ed25519 ..." -p 22:22 \ -d \ - ubuntu-sshd-image + ghcr.io/fabled-se/ubuntu-sshd-image:latest ``` -