FROM debian:12
RUN apt-get update -y && apt-get install git-core openssh-server sudo curl -y
RUN curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
RUN apt-get install nodejs -y
RUN echo "/usr/bin/git-shell" >> /etc/shells
RUN adduser git
RUN usermod -u 1000 git
RUN usermod --shell /usr/bin/sh git
RUN mkdir /home/git/repos
RUN chown git:git -R /home/git/repos
RUN usermod --home /home/git/repos git
RUN sed -i -E 's/auth required pam_shells.so/auth sufficient pam_shells.so/' /etc/pam.d/chsh
RUN sed -i -E 's/#?PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
RUN echo "AllowUsers root git" >> /etc/ssh/sshd_config
RUN echo "AuthorizedKeysFile .ssh/authorized_keys /home/git/.ssh/authorized_keys" >> /etc/ssh/sshd_config
RUN sed -i -E 's|session optional pam_motd.so motd=/run/motd.dynamic|#session optional pam_motd.so motd=/run/motd.dynamic|' /etc/pam.d/sshd
RUN sed -i -E 's|session optional pam_motd.so noupdate|#session optional pam_motd.so noupdate|' /etc/pam.d/sshd
RUN echo "" > /etc/motd
WORKDIR /home/git/
RUN mkdir git-shell-commands/
COPY ./data/git-shell-commands/no-interactive-login /home/git/git-shell-commands/no-interactive-login
RUN chown git:git git-shell-commands/no-interactive-login
RUN chmod +x git-shell-commands/no-interactive-login
COPY ./data/ssh_command /usr/bin/
RUN chmod +x /usr/bin/ssh_command
RUN mkdir -p .ssh
RUN chmod 700 .ssh
COPY ./data/authorized_keys .ssh/authorized_keys
RUN chmod 600 .ssh/authorized_keys
RUN chown git:git -R .ssh
USER root
WORKDIR /home/git
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]