Skip to content

Commit

Permalink
Take PUBLIC_SSH_KEY env var instead of authorized_keys mount
Browse files Browse the repository at this point in the history
  • Loading branch information
zapling committed Mar 7, 2024
1 parent 31f5476 commit 0b4d2fb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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" ]
14 changes: 4 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```

0 comments on commit 0b4d2fb

Please sign in to comment.