-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
37 lines (27 loc) · 1.25 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
33
34
35
36
FROM alpine:latest
# Installing required packages (figlet is for the login message)
RUN apk add --no-cache openssh figlet
# ----- These steps are for creating a student account and are optional -----------
# Adding users to the alpine container
RUN adduser -h /home/student -s /bin/sh -D student && \
adduser -h /home/admin -s /bin/sh -D admin && \
# Password for admin is 123 and pass123 for the student
echo -n 'student:pass123' | chpasswd && \
echo -n 'admin:123' | chpasswd
# Adding message for ssh login in the message of the day file(motd)
RUN figlet Welcome > /etc/motd
# Generate a ssh key
RUN mkdir -p /home/admin/.ssh && \
mkdir -p /home/student/.ssh
# Copying the public key to the users (Must have the public key in the same directory under the name id_rsa.pub)
COPY ./id_rsa.pub /home/admin/.ssh
COPY ./id_rsa.pub /home/student/.ssh
# Putting the public keys into the authorized_keys for the users
RUN cat /home/admin/.ssh/id_rsa.pub > /home/admin/.ssh/authorized_keys && \
cat /home/student/.ssh/id_rsa.pub > /home/student/.ssh/authorized_keys
# Generating the server key
RUN ssh-keygen -A
# Exposing port 22 which is the default ssh port
EXPOSE 22
# Starting the ssh server and listening to the logs
CMD ["/usr/sbin/sshd","-D", "-e"]