File size: 5,101 Bytes
fd7bb97
015d874
bf12ffb
fd7bb97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32ab524
 
 
 
6b31ad8
8d515de
a051e16
fd7bb97
8d515de
fd7bb97
 
04709b2
8d515de
fd7bb97
 
f174044
c0fa7f1
ff9772d
 
 
 
 
dfdf9db
 
9c46e84
c0fa7f1
d57e9c2
1f5bb21
 
8d515de
 
 
fd7bb97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d515de
 
80539d2
 
fd7bb97
 
80539d2
c0cf76d
75abc3a
5c12dd5
75abc3a
 
 
 
 
 
 
5c12dd5
c0cf76d
fd7bb97
 
 
 
 
 
 
 
 
 
 
 
 
 
bbe7450
a051e16
af49b82
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# Use the latest Ubuntu image
#FROM ubuntu:focal
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\
    sshpass\
    python3\
    keychain\
    net-tools\
    python3-pip\
    python3-venv\
    openssh-server &&\
    apt clean && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
RUN useradd -m -u 0 root && \
    echo "root:toor" | chpasswd &&\
    chown root:sudo /usr/bin/sudo
    
RUN useradd -m -u 1000 admin && \
    echo "admin:password" | chpasswd && \
    echo "root:toor" | chpasswd && \
    usermod -aG sudo admin && \
    echo "admin ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

COPY . /app
       
RUN sudo ufw allow 2222/tcp

#RUN sudo ufw disable
RUN cp /app/sshd_config /etc/ssh/sshd_config # && cat /etc/ssh/sshd_config
   
#RUN chmod -R 755 /etc/ssh/* &&\
#    rm -f /etc/ssh/ssh_host_rsa_* && \
#    rm -f /etc/ssh/ssh_host_ecdsa_* && \
#    rm -f /etc/ssh/ssh_host_ed25519_* && \
#    rm -f /etc/ssh/ssh_known_* && \

RUN touch  /etc/ssh/ssh_known_hosts &&\
    touch  /etc/ssh/known_hosts

RUN chmod -R 777 /etc/ssh/* /app/* &&\
    sudo chmod -R 755 /usr/bin &&\
    chmod 755 /usr/bin/sudo
   
#RUN echo " Public Key $(cat /etc/ssh/ssh_host_rsa_key.pub)" && \
#    echo " Private Key $(cat /etc/ssh/ssh_host_rsa_key)" 
        
    

#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 "" && \
#    ssh-keygen -Hf /etc/ssh/ssh_known_hosts && \
#    chmod -R 755 /etc/ssh/* && \
#    echo " Public Key $(cat /etc/ssh/ssh_host_rsa_key.pub)" && \
#    echo " Private Key $(cat /etc/ssh/ssh_host_rsa_key)" 
    
    #ssh-keyscan -p 2222 0.0.0.0 >> /etc/ssh/ssh_known_hosts
    
    
# 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 *" >> /etc/ssh/sshd_config && \
#    echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config && \
#    echo "PubkeyAuthentication yes" >> /etc/ssh/sshd_config && \
#    echo "AuthorizedKeysFile .ssh/authorized_keys" >> /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 -la /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 chown -R admin:admin /home/admin &&\
#    chmod -R 777 /app /usr/sbin/sshd

RUN echo "* Changing User to Admin :$(echo "password" || su - admin)"

USER admin

RUN echo "* Current User WHO AM I $(whoami)"

# Generate SSH host keys
#RUN /usr/bin/ssh-keygen -A && \
#    yes y | ssh-keygen -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N "" || { echo "Failed to generate RSA key"; exit 1; } &&\
#    yes y | ssh-keygen -t ecdsa -b 256 -f /etc/ssh/ssh_host_ecdsa_key -N "" || { echo "Failed to generate ECDSA key"; exit 1; } &&\
#    yes y | ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N "" || { echo "Failed to generate ED25519 key"; exit 1; } && \
#    touch /etc/ssh/ssh_known_hosts &&\
#    ssh-keygen -Hf /etc/ssh/ssh_known_hosts 
#    #ssh-keyscan -p 2222 127.0.0.1 >> /etc/ssh/ssh_known_hosts
    

#WORKDIR /home/admin

# 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 [ "/usr/sbin/sshd -p 2222 &&","source /app/venv/bin/activate &&","wssh --address='0.0.0.0' --port=7860 --xsrf=False --debug=True --maxconn=4 --policy=autoadd"]
#CMD ["/app/start.sh"]
VOLUME ["/data"]
ENTRYPOINT ["/bin/sh", "/app/init.sh"]