构建具有SSH功能的RockyLinux镜像
时间:2022-08-30 11:09 来源:csdn.net 作者:白额卷尾猴
自从CentOS8 停更以后,很多CentOS8的用户便转到了Rocky Linux,工作需要,做了一个具有SSH功能的RockyLinux 镜像。Dockerfile的代码如下:
FROM rockylinux:latest
MAINTAINER This is RockyLinux:ssh
#将源改为国内的阿里源
RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/Rocky-*.repo
RUN dnf makecache
RUN dnf install -y openssh* net-tools lsof telnet passwd systemd
#修改root用户密码
RUN echo "123456" | passwd --stdin root
#设置不使用ssh服务端的pam模块
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
#缺少下面两句ssh登录会反应慢
RUN sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
RUN sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config
#创建非对称秘钥
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
#关闭pam.d的ssh会话模块
RUN sed -i '/^session\s\+required\s\+pam_loginuid.so/s/^ /#/' /etc/pam.d/sshd
#创建ssh工作目录并设置权限
RUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh
#暴露端口
EXPOSE 22
#开启sshd服务
CMD ["/usr/sbin/sshd","-D"]
#生成镜像
docker build --no-cache --rm -t rockylinux8_ssh .
#运行容器
docker run -d --privileged -p22:22 -h rockylinux8ssh --name rockylinux8ssh rockylinux8_ssh
(责任编辑:IT)
自从CentOS8 停更以后,很多CentOS8的用户便转到了Rocky Linux,工作需要,做了一个具有SSH功能的RockyLinux 镜像。Dockerfile的代码如下: FROM rockylinux:latest MAINTAINER This is RockyLinux:ssh #将源改为国内的阿里源 RUN sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \ -i.bak \ /etc/yum.repos.d/Rocky-*.repo RUN dnf makecache RUN dnf install -y openssh* net-tools lsof telnet passwd systemd #修改root用户密码 RUN echo "123456" | passwd --stdin root #设置不使用ssh服务端的pam模块 RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config #缺少下面两句ssh登录会反应慢 RUN sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config RUN sed -i 's/GSSAPIAuthentication yes/GSSAPIAuthentication no/g' /etc/ssh/sshd_config #创建非对称秘钥 RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key #关闭pam.d的ssh会话模块 RUN sed -i '/^session\s\+required\s\+pam_loginuid.so/s/^ /#/' /etc/pam.d/sshd #创建ssh工作目录并设置权限 RUN mkdir -p /root/.ssh && chown root.root /root && chmod 700 /root/.ssh #暴露端口 EXPOSE 22 #开启sshd服务 CMD ["/usr/sbin/sshd","-D"] #生成镜像 docker build --no-cache --rm -t rockylinux8_ssh . #运行容器 docker run -d --privileged -p22:22 -h rockylinux8ssh --name rockylinux8ssh rockylinux8_ssh (责任编辑:IT) |