This is loosely based on, or rather inspired by linuxserver/ssh-server.
The main difference is that running as root is allowed, for SSHFS among others.
Also you can set the port the SSH daemon listens on inside the container,
which may come in handy if you use this container as a way to debug a pod
running on the host network namespace (if you blindly listen on 22/tcp
you
may end up competing with the host's SSH service - which you probably don't
want to, ever.).
docker run -ti --rm \
-v "$PWD/config:/config" \
-p "22222:22222/tcp" \
-e SSHD_PORT="22222" \
-e AUTHORIZED_KEYS="ssh-ed25519 XXX" \
-e GITHUB_USERNAME="pschmitt" \
-e USERNAME="user01" \
-e PASSWORD="somethingImpossibleToRemember" \
-e PERMIT_ROOT_LOGIN="no" \
-e PUID="1000" \
-e PGID="1000" \
pschmitt/sshd
Then, to connect using the example above - from the same machine:
ssh -p 22222 user01@localhost
If you need to set the DNS ndots value (which you may since this container is
based on Alpine) you can so using the DNS_NDOTS
env var.
Example:
docker run -ti --rm \
-p "22222:22222/tcp" \
-e SSHD_PORT="22222" \
-e USERNAME="user01" \
-e PASSWORD="somethingImpossibleToRemember" \
-e DNS_NDOTS="1" \
pschmitt/sshd