34 lines
876 B
Plaintext
34 lines
876 B
Plaintext
FROM centos:7
|
|
|
|
# 设置环境变量(登录密码)
|
|
ARG ROOT_PASSWORD
|
|
|
|
# 切换镜像源
|
|
RUN mv /etc/yum.repos.d/* /tmp \
|
|
&& curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
|
|
|
|
# 安装SSH服务及相关工具
|
|
RUN yum install -y \
|
|
openssh-server \
|
|
openssh-clients \
|
|
passwd \
|
|
sudo \
|
|
vim \
|
|
net-tools \
|
|
iproute \
|
|
which \
|
|
&& yum clean all
|
|
|
|
# 配置SSH服务
|
|
RUN ssh-keygen -A \
|
|
&& mkdir -p /var/run/sshd \
|
|
&& echo "root:${ROOT_PASSWORD}" | chpasswd \
|
|
&& sed -i 's/#PermitRootLogin yes/PermitRootLogin yes/' /etc/ssh/sshd_config \
|
|
&& sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config \
|
|
&& sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config
|
|
|
|
# 开放SSH端口
|
|
EXPOSE 22
|
|
|
|
# 启动SSH服务
|
|
CMD ["/usr/sbin/sshd", "-D"] |