Ubuntu / Dockerfile
privateone's picture
Update Dockerfile
175a5fd verified
raw
history blame
4.68 kB
# Use the latest Ubuntu image
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\
python3\
keychain\
net-tools\
python3-pip\
python3-venv\
openssh-server &&\
apt clean && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create the 'admin' user with home directory and password, and 'administrator' group
#RUN useradd -m -s /bin/bash admin && \
# echo 'admin:password' | chpasswd && \
# useradd -m -s /bin/bash ubuntu && \
# echo 'ubuntu:password' | chpasswd && \
# groupadd administrator && \
# usermod -aG administrator,sudo admin && \
# usermod -aG administrator,sudo ubuntu
# Create the 'admin' and 'ubuntu' users with home directories and passwords, and add them to the 'sudo' group
#RUN groupadd -r admin && useradd -r -g users admin && \
# echo 'admin:password' | chpasswd && \
# echo 'ubuntu:password' | chpasswd && \
RUN useradd -m -s /bin/bash admin && \
usermod -aG sudo admin && \
echo "admin:password" | sudo chpasswd && \
echo "admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
#RUN id -u ubuntu &>/dev/null || useradd -m -s /bin/bash ubuntu && \
# usermod -aG sudo ubuntu && \
# echo "ubuntu:password" | chpasswd && \
# echo "ubuntu ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
#RUN echo "password" | su - ubuntu -c "whoami"
# Copy the application code to the container
COPY . /app
# Create necessary directories and set permissions
RUN mkdir -p /var/run/sshd /app /app/users/sshs /app/ssh && \
chmod -R 777 /app
# touch /etc/sudoers
# Grant full sudo access to the 'administrator' group
RUN sed -i 's/Defaults !requiretty/Defaults requiretty/' /etc/sudoers && \
echo 'admin ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
#RUN echo "%administrator ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
# Generate SSH host keys
#RUN ssh-keygen -A &&\
# sudo ufw allow 2222/tcp
# Generate SSH keys
#RUN ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key && \
# ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key && \
# ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key
#RUN ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" -y && \
# ssh-keygen -q -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" -y && \
# ssh-keygen -q -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" -y
# 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 admin" >> /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 -l /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 chmod -R 777 /app
USER admin
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 ""
# 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 ["/app/start.sh"]