Ubuntu / Dockerfile
privateone's picture
Update Dockerfile
32ab524 verified
# Use the latest Ubuntu image
#FROM ubuntu:focal
FROM ubuntu:focal
# Set environment variable to avoid interactive prompts
ENV DEBIAN_FRONTEND=noninteractive
# Set timezone to your desired timezone (e.g., "America/New_York")
#RUN ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime && \
# echo "India/Kolkata" > /etc/timezone
# Update package list, install required packages, and clean up
RUN apt-get update && \
apt-get install -y \
ufw\
sudo\
bash \
passwd\
sshpass\
python3\
keychain\
net-tools\
python3-pip\
python3-venv\
openssh-server &&\
apt clean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN useradd -m -u 0 root && \
echo "root:toor" | chpasswd &&\
chown root:sudo /usr/bin/sudo
RUN useradd -m -u 1000 admin && \
echo "admin:password" | chpasswd && \
echo "root:toor" | chpasswd && \
usermod -aG sudo admin && \
echo "admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
COPY . /app
RUN sudo ufw allow 2222/tcp
#RUN sudo ufw disable
RUN cp /app/sshd_config /etc/ssh/sshd_config # && cat /etc/ssh/sshd_config
#RUN chmod -R 755 /etc/ssh/* &&\
# rm -f /etc/ssh/ssh_host_rsa_* && \
# rm -f /etc/ssh/ssh_host_ecdsa_* && \
# rm -f /etc/ssh/ssh_host_ed25519_* && \
# rm -f /etc/ssh/ssh_known_* && \
RUN touch /etc/ssh/ssh_known_hosts &&\
touch /etc/ssh/known_hosts
RUN chmod -R 777 /etc/ssh/* /app/* &&\
sudo chmod -R 755 /usr/bin &&\
chmod 755 /usr/bin/sudo
#RUN echo " Public Key $(cat /etc/ssh/ssh_host_rsa_key.pub)" && \
# echo " Private Key $(cat /etc/ssh/ssh_host_rsa_key)"
#RUN yes y | ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" && \
# yes y | ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" && \
# yes y | ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" && \
# ssh-keygen -Hf /etc/ssh/ssh_known_hosts && \
# chmod -R 755 /etc/ssh/* && \
# echo " Public Key $(cat /etc/ssh/ssh_host_rsa_key.pub)" && \
# echo " Private Key $(cat /etc/ssh/ssh_host_rsa_key)"
#ssh-keyscan -p 2222 0.0.0.0 >> /etc/ssh/ssh_known_hosts
# Secure SSH Configuration
#RUN sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config && \
# sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
# sed -i 's/#ChallengeResponseAuthentication yes/ChallengeResponseAuthentication no/' /etc/ssh/sshd_config && \
# sed -i 's/#UsePAM yes/UsePAM no/' /etc/ssh/sshd_config && \
# sed -i 's/#Port 22/Port 2222/' /etc/ssh/sshd_config && \
# echo "AllowUsers *" >> /etc/ssh/sshd_config && \
# echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config && \
# echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config && \
# echo "AuthorizedKeysFile .ssh/authorized_keys" >> /etc/ssh/sshd_config && \
# Copy all the contents of /etc/ssh to /app/ssh
#RUN mkdir -p /app/ssh && cp -r /etc/ssh/* /app/ssh
# Set the permissions for the SSH keys
#RUN chmod 777 /etc/ssh/ssh_* && \
# touch /app/ssh/ssh_known_hosts && \
# chmod 777 /app/ssh/ssh_* && \
# chmod 777 /home
# List contents of /etc/ssh and /app/ssh
RUN ls -la /etc/ssh/ # && ls -l /app/ssh/
# Install WebSSH
RUN python3 -m venv /app/WebSSHEnv && \
/app/WebSSHEnv/bin/pip install --no-cache-dir --upgrade pip && \
/app/WebSSHEnv/bin/pip install --no-cache-dir -r /app/WebSSH/requirements.txt && \
/app/WebSSHEnv/bin/pip list
# Expose the new SSH port
EXPOSE 2222
EXPOSE 7860
#RUN chown -R admin:admin /home/admin &&\
# chmod -R 777 /app /usr/sbin/sshd
RUN echo "* Changing User to Admin :$(echo "password" || su - admin)"
USER admin
RUN echo "* Current User WHO AM I $(whoami)"
# Generate SSH host keys
#RUN /usr/bin/ssh-keygen -A && \
# yes y | ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" || { echo "Failed to generate RSA key"; exit 1; } &&\
# yes y | ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" || { echo "Failed to generate ECDSA key"; exit 1; } &&\
# yes y | ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" || { echo "Failed to generate ED25519 key"; exit 1; } && \
# touch /etc/ssh/ssh_known_hosts &&\
# ssh-keygen -Hf /etc/ssh/ssh_known_hosts
# #ssh-keyscan -p 2222 127.0.0.1 >> /etc/ssh/ssh_known_hosts
#WORKDIR /home/admin
# Generate SSH keys
#RUN ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" -y && \
# ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" -y && \
# ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" -y
# Copy the start.sh script
#RUN chmod 777 /app/venv/lib/python3.12/site-packages/
#RUN touch /app/venv/lib/python3.12/site-packages/known_hosts
#RUN chmod 777 /app/venv/lib/python3.12/site-packages/known_hosts
#CMD [ "/usr/sbin/sshd -p 2222 &&","source /app/venv/bin/activate &&","wssh --address='0.0.0.0' --port=7860 --xsrf=False --debug=True --maxconn=4 --policy=autoadd"]
#CMD ["/app/start.sh"]
VOLUME ["/data"]
ENTRYPOINT ["/bin/sh", "/app/init.sh"]