-
Notifications
You must be signed in to change notification settings - Fork 14
/
Dockerfile
32 lines (27 loc) · 1.23 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Use an official Ubuntu base image
FROM ubuntu:24.04
# Set environment variables to avoid interactive prompts during installation
ENV DEBIAN_FRONTEND=noninteractive
ENV SSH_USERNAME="ubuntu"
ENV SSHD_CONFIG_ADDITIONAL=""
# Install OpenSSH server, clean up, create directories, set permissions, and configure SSH
RUN apt-get update \
&& apt-get install -y iproute2 iputils-ping openssh-server telnet \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& mkdir -p /run/sshd \
&& chmod 755 /run/sshd \
&& if ! id -u "$SSH_USERNAME" > /dev/null 2>&1; then useradd -ms /bin/bash "$SSH_USERNAME"; fi \
&& chown -R "$SSH_USERNAME":"$SSH_USERNAME" /home/"$SSH_USERNAME" \
&& chmod 755 /home/"$SSH_USERNAME" \
&& mkdir -p /home/"$SSH_USERNAME"/.ssh \
&& chown "$SSH_USERNAME":"$SSH_USERNAME" /home/"$SSH_USERNAME"/.ssh \
&& echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config \
&& echo "PermitRootLogin no" >> /etc/ssh/sshd_config
# Copy the script to configure the user's password and authorized keys
COPY configure-ssh-user.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/configure-ssh-user.sh
# Expose SSH port
EXPOSE 22
# Start SSH server
CMD ["/usr/local/bin/configure-ssh-user.sh"]