zoukankan      html  css  js  c++  java
  • 容器搭建sshd服务

    容器搭建sshd服务

    通过外部服务器访问docker容器内部,下面以centos使用ssh连接为例:

    宿主机

    1、准备一个centos镜像

    • docker pull centos:7

    2、镜像容器化

    docker run -it --name con_ssh centos:7 bash

    容器内

    1、容器中安装sshd

    • yum install passwd openssl openssh-server -y

    2、启动sshd

    • /usr/sbin/sshd -D &

    • 报错如下:

      [root@ec5a752c0605 /]# /usr/sbin/sshd
      Could not load host key: /etc/ssh/ssh_host_rsa_key
      Could not load host key: /etc/ssh/ssh_host_ecdsa_key
      Could not load host key: /etc/ssh/ssh_host_ed25519_key

    执行以下命令解决该问题:

    [root@ec5a752c0605 ~]# ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''
    [root@ec5a752c0605 ~]# ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
    [root@ec5a752c0605 ~]# ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''
    

    3、修改 /etc/ssh/sshd_config 配置信息

    • UsePAM yes 改为 UsePAM no
      • sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config

    修改完后,重新启动sshd

    4、修改root密码

    • [root@ec5a752c0605 ~]# passwd rot

      输入密码

    此时可以将该容器打成镜像,也可以后续将步骤整理成Dockerfile。

    返回到宿主机,使用ssh root@容器ip

    容器ip查看方式:docker inspect 容器名

  • 相关阅读:
    zend studio常见问题解答
    瀑布流插件(jquery.masonry.js)
    仿jQuery中undelegate()方法功能的函数
    Linux 常用命令
    linux debugfs 找回rm 的文件
    jq 添加和移除样式
    CentOS 搭建 nginx python django web server
    Linux vim 配置文件
    CentOS 安装python 3.3.2
    login.defs和shadow文件区别
  • 原文地址:https://www.cnblogs.com/jmtang/p/13704393.html
Copyright © 2011-2022 走看看