Skip to content

Instantly share code, notes, and snippets.

@hortinstein
Created January 27, 2019 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hortinstein/5d92bf54773575f5edf8e5070d80170c to your computer and use it in GitHub Desktop.
Save hortinstein/5d92bf54773575f5edf8e5070d80170c to your computer and use it in GitHub Desktop.
ssh docker
FROM build:latest
MAINTAINER Alex Hortin
EXPOSE 22
EXPOSE 80
##############################
# installing tiny init (tini)
##############################
RUN apk add --update tini gcc make
##############################
#configuring ssh
##############################
# add openssh and clean
RUN apk add --update openssh \
&& rm -rf /tmp/* /var/cache/apk/*
# add entrypoint and startup script
ADD docker-entrypoint.sh /usr/local/bin
ADD startup.sh /usr/local/bin
#make sure we get fresh keys
RUN rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key
#setup the ssh server
RUN mkdir /root/.ssh
RUN chmod 0700 /root/.ssh
COPY ./ssh/id_rsa.pub /root/.ssh/authorized_keys
RUN chmod 0600 /root/.ssh/authorized_keys
##############################
# installing vulnerable web server
##############################
COPY executables/central_logging_server /root/server
ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["startup.sh"]
-------------------------------------------startup.sh
#!/bin/sh
python2.7 root/server &
/usr/sbin/sshd -D
-------------------------------------------
#!/bin/sh
if [ ! -f "/etc/ssh/ssh_host_rsa_key" ]; then
# generate fresh rsa key
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
fi
if [ ! -f "/etc/ssh/ssh_host_dsa_key" ]; then
# generate fresh dsa key
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
fi
#prepare run dir
if [ ! -d "/var/run/sshd" ]; then
mkdir -p /var/run/sshd
fi
/sbin/tini --
exec "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment