新增Docker ssh管理
This commit is contained in:
34
Docker/Dockerfile/Centos/Dockerfile-ssh
Normal file
34
Docker/Dockerfile/Centos/Dockerfile-ssh
Normal file
@@ -0,0 +1,34 @@
|
||||
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"]
|
||||
Reference in New Issue
Block a user