Dockerfile 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. FROM alpine:latest
  2. COPY --chown=root:root server/ssh /etc/ssh/
  3. COPY --chown=root:root server/script /opt/sshnet
  4. COPY user/sshnet /home/sshnet/.ssh
  5. RUN apk update && apk upgrade --no-cache && \
  6. apk add --no-cache syslog-ng && \
  7. # install and configure sshd
  8. apk add --no-cache openssh && \
  9. # install openssh-server-pam to allow for keyboard-interactive authentication
  10. apk add --no-cache openssh-server-pam && \
  11. dos2unix /etc/ssh/* && \
  12. chmod 400 /etc/ssh/ssh*key && \
  13. sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
  14. sed -i 's/#LogLevel\s*INFO/LogLevel DEBUG3/' /etc/ssh/sshd_config && \
  15. # Set the default RSA key
  16. echo 'HostKey /etc/ssh/ssh_host_rsa_key' >> /etc/ssh/sshd_config && \
  17. chmod 646 /etc/ssh/sshd_config && \
  18. # install and configure sudo
  19. apk add --no-cache sudo && \
  20. addgroup sudo && \
  21. # allow root to run any command
  22. echo 'root ALL=(ALL) ALL' > /etc/sudoers && \
  23. # allow everyone in the 'sudo' group to run any command without a password
  24. echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
  25. # add user to run most of the integration tests
  26. adduser -D sshnet && \
  27. passwd -u sshnet && \
  28. echo 'sshnet:ssh4ever' | chpasswd && \
  29. dos2unix /home/sshnet/.ssh/* && \
  30. chown -R sshnet:sshnet /home/sshnet && \
  31. chmod -R 700 /home/sshnet/.ssh && \
  32. chmod -R 644 /home/sshnet/.ssh/authorized_keys && \
  33. # add user to administer container (update configs, restart sshd)
  34. adduser -D sshnetadm && \
  35. passwd -u sshnetadm && \
  36. echo 'sshnetadm:ssh4ever' | chpasswd && \
  37. addgroup sshnetadm sudo && \
  38. dos2unix /opt/sshnet/* && \
  39. # install shadow package; we use chage command in this package to expire/unexpire password of the sshnet user
  40. apk add --no-cache shadow && \
  41. # allow us to use telnet command; we use this in the remote port forwarding tests
  42. apk --no-cache add busybox-extras && \
  43. # install full-fledged ps command
  44. apk add --no-cache procps
  45. EXPOSE 22 22
  46. ENTRYPOINT ["/opt/sshnet/start.sh"]