Skip to content

Commit 1be480d

Browse files
committed
Creating the password in runtime
1 parent 6f6595f commit 1be480d

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

Dockerfile

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
# Use Ubuntu as the base image
22
FROM ubuntu:latest AS runner
33

4-
# Install SSH Server
4+
# Set noninteractive mode for apt-get
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Install SSH Server and other utilities
58
RUN apt-get update && \
69
apt-get install -y \
10+
curl \
11+
net-tools \
712
openssh-server \
813
sudo \
914
vim \
10-
curl \
1115
wget \
12-
net-tools \
1316
&& rm -rf /var/lib/apt/lists/*
1417

1518
# Create a user (e.g., 'dev') and set the password
16-
RUN useradd -rm -d /home/dev -s /bin/bash -g root -G sudo -u 1001 dev
19+
RUN useradd -rm -d /home/dev -s /bin/bash -g root -G sudo -u 1001 dev && \
20+
mkdir -p /home/dev/.ssh && \
21+
chmod 700 /home/dev/.ssh
1722

1823
# SSH login fix. Otherwise, the user is kicked off after login
1924
RUN mkdir /var/run/sshd
2025

21-
# Change SSH settings to allow port forwarding
22-
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \
26+
# Update SSH settings to restrict authentication to public key only
27+
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin no/' /etc/ssh/sshd_config && \
2328
sed -i 's/#AllowTcpForwarding no/AllowTcpForwarding yes/' /etc/ssh/sshd_config && \
2429
sed -i 's/#PermitTunnel no/PermitTunnel yes/' /etc/ssh/sshd_config
2530

31+
# Add the custom entrypoint script
2632
COPY entrypoint.sh /entrypoint.sh
2733
RUN chmod +x /entrypoint.sh
2834

entrypoint.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#!/bin/bash
22

3-
echo "Setting SSH password"
4-
echo "dev:${DEV_TUNNEL_SSH_PASSWORD}" | chpasswd
3+
# Set SSH password if the environment variable is defined
4+
if [ -n "${DEV_TUNNEL_SSH_PASSWORD}" ]; then
5+
echo "Setting SSH password for dev user"
6+
echo "dev:${DEV_TUNNEL_SSH_PASSWORD}" | chpasswd
7+
fi
58

69
# Start SSH service
710
echo "Starting SSH service"
8-
/usr/sbin/sshd -D
11+
/usr/sbin/sshd -D

0 commit comments

Comments
 (0)