Dockerfile使用ssh构建docker archlinux镜像
之乎者也 Lv3

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
# sshd on archlinux

FROM archlinux:latest

# 更新源
RUN pacman -Syy

# 安装 openssh
RUN pacman -S --noconfirm openssh

# Generate host keys
RUN ssh-keygen -A

RUN ssh-keygen -b 4096 -t rsa -N '' -f /root/.ssh/id_rsa -q
RUN cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
RUN chmod 600 /root/.ssh/authorized_keys
RUN chmod 700 /root/.ssh

# Add password to root user
RUN echo 'root:roottoor' | chpasswd

# 安装ohmyzsh
RUN pacman -S --noconfirm curl
RUN pacman -S --noconfirm zsh
RUN pacman -S --noconfirm git
RUN pacman -S --noconfirm nano

WORKDIR /root
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
RUN sed -i 's|^ZSH_THEME="robbyrussell"|ZSH_THEME="ys"|' /root/.zshrc
RUN sed -i 's|^plugins=(git)|plugins=(\ngit\nzsh-syntax-highlighting\nzsh-autosuggestions\n)|' /root/.zshrc
RUN chsh -s /bin/zsh

# Fix sshd
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
RUN sed -i 's|^#Port 22|Port 22222|' /etc/ssh/sshd_config
RUN sed -i 's|^#PubkeyAuthentication|PubkeyAuthentication|' /etc/ssh/sshd_config

WORKDIR /home

# Run openssh daemon
CMD ["/usr/sbin/sshd", "-D"]