File size: 2,296 Bytes
15d9364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a6514f8
 
 
 
15d9364
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Use the official Ubuntu base image
FROM ubuntu:latest

# Set the maintainer label
LABEL maintainer="your-email@example.com"

# Prevent prompts during package installation
ARG DEBIAN_FRONTEND=noninteractive

#RUN useradd -rm -d /home/ubuntu -s /bin/bash -g root -G sudo -u 1000 ubuntu && \
#    echo 'root:password' | chpasswd
#    echo 'ubuntu:ubuntu' | chpasswd && \

# Copy the application code to the container
COPY . /app

# Install necessary packages
RUN apt update && apt install -y \
    openssh-server \
    openssh\
    sudo \
    bash \
    python3 \
    python3-pip \
    python3-venv \
    net-tools && \
    apt clean && \
    rm -rf /var/lib/apt/lists/*

    
RUN useradd -ms /bin/bash ubuntu

# SSH Configuration
RUN mkdir -p /var/run/sshd /app /app/ssh
RUN chmod -R 777 /app


# Generate SSH keys
RUN ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" && \
    ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" && \
    ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""

# 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_host_* && \
    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/venv && \
    /app/venv/bin/pip install --no-cache-dir --upgrade pip && \
    /app/venv/bin/pip install --no-cache-dir webssh && \
    /app/venv/bin/pip list

# Set the working directory
WORKDIR /app

USER root

# Expose the port the app runs on
EXPOSE 7860

# Expose the port the app runs on
EXPOSE 2222

# Define the command to run the application
CMD ["/app/start.sh"]