# Use the official image as a parent image
FROM ubuntu:22.04

ENV DEBIAN_FRONTEND=noninteractive

# Update the system
RUN apt-get update && apt-get upgrade -y

# Setting Utils
RUN apt-get install -y vim net-tools sudo

# Install OpenSSH Server
RUN apt-get install -y openssh-server

# Set up configuration for SSH
RUN mkdir /var/run/sshd
RUN echo 'root:!@#gds$%^' | chpasswd

# Add 'gds' user and set password
RUN useradd -m -s /bin/bash gds
RUN echo 'gds:gds12!@' | chpasswd

# Add 'gds' user to sudoers (Remove NOPASSWD to require password for sudo)
RUN usermod -aG sudo gds

# Modify sudoers to require password for sudo (default behavior, no need for specific line)

# Disable 'su' command for 'gds' user by restricting access to 'root'
RUN dpkg-reconfigure -plow libpam-runtime
RUN echo "gds ALL=(ALL) ALL" >> /etc/sudoers  # Allow sudo, with password
RUN chmod 750 /bin/su  # Restrict access to 'su' for non-root users

# Set SSH to allow gds login and permit root login
RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN echo "AllowUsers gds" >> /etc/ssh/sshd_config

# SSH login fix. Otherwise, user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

# Expose the SSH port
EXPOSE 22 52530 52532 52533 53306

# Run SSH
CMD ["/usr/sbin/sshd", "-D"]
