-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathDockerfile.ssh-test
More file actions
39 lines (31 loc) · 1.11 KB
/
Dockerfile.ssh-test
File metadata and controls
39 lines (31 loc) · 1.11 KB
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
33
34
35
36
37
38
39
FROM ubuntu:22.04
# Disable IPv6 to avoid connection issues
RUN echo 'Acquire::ForceIPv4 "true";' > /etc/apt/apt.conf.d/99force-ipv4
# Install SSH server and dependencies with retries
RUN apt-get update && \
apt-get install -y \
openssh-server \
sudo \
curl \
git \
vim \
net-tools && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Create SSH directory
RUN mkdir -p /var/run/sshd
# Create test user
RUN useradd -rm -d /home/testuser -s /bin/bash -g users -G sudo -u 1001 testuser && \
echo 'testuser:testpass' | chpasswd
# Allow password authentication
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# Create .ssh directory with proper permissions
RUN mkdir -p /home/testuser/.ssh && \
chown -R testuser:users /home/testuser/.ssh && \
chmod 700 /home/testuser/.ssh
# Expose SSH port
EXPOSE 22
# Start SSH service
CMD ["/usr/sbin/sshd", "-D"]