# Use AlmaLinux 9 as base image
FROM almalinux:9
ENV WORKDIR /root/

# Set the working directory
WORKDIR $WORKDIR

RUN export PATH=.:$PATH

RUN dnf -y update && dnf -y install net-tools wget openssh-server sudo passwd && dnf clean all
RUN useradd -rm -d /home/test -s /bin/bash -g root -G wheel -u 1000 test
RUN echo 'test:test' | chpasswd

# generate server keys
RUN ssh-keygen -A
RUN ssh-keygen -t rsa -q -f "$HOME/.ssh/id_rsa" -N ""

# allow root to login
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/g' /etc/ssh/sshd_config

EXPOSE 22
CMD ["/usr/bin/sudo", "/usr/sbin/sshd", "-D", "-o", "ListenAddress=0.0.0.0"]
