Skip to content

Instantly share code, notes, and snippets.

@caliburn1994
Last active October 28, 2020 16:14
Show Gist options
  • Save caliburn1994/91e8b8d1205ca03c2acee2a7d71318a3 to your computer and use it in GitHub Desktop.
Save caliburn1994/91e8b8d1205ca03c2acee2a7d71318a3 to your computer and use it in GitHub Desktop.
Docker SSH Server + public key authentication . login as a normal user
user=www
mkdir data keys public
# copy public key to current dir, for safe.
cp ${HOME}/.ssh/id_rsa.pub public/
docker run -ti -p 2222:22 \
-v $(pwd)/public/id_rsa.pub:/etc/authorized_keys/$(user) \
-v $(pwd)/keys/:/etc/ssh/keys \
-v $(pwd)/data/:/data/ \
-e SSH_USERS="${user}:48:48" \
--name my-ssh \
docker.io/panubo/sshd:1.3.0
user=www
docker exec my-ssh chown ${user}:${user} /etc/authorized_keys/${user}
ssh ${user}@localhost -p 2222
# stop
docker stop my-ssh
docker remove my-ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment