xywuyiba8 发表于 2018-5-30 10:49:41

创建不用ssh密码登陆的docker镜像

  操作系统:vm centos6.5

  容器:docker
  前提:可以ssh的docker镜像已经创建
  

  第一种方法,手动创建

  

  1.在宿主机上生成新的密钥和公钥
###ssh-keygen [-q] [-b bits] -t type [-N new_passphrase] [-C comment] [-foutput_keyfile]
#ssh-keygen的具体用法参考官方文档
ssh-keygen -q -N "" -t dsa -f /root/.ssh/id_dsa  

  2.然后把公钥放在创建好的docker容器中去
ssh -o StrictHostKeyChecking=no root@172.17.0.2
mkdir -p /root/.ssh
echo "..." >> /root/.ssh/authorized_keys  

  3.在宿主机上测试ssh连接

$ ssh 172.17.0.2
Last login: Sat Aug 2 11:16:10 2014 from 172.17.42.1
$  

  第二种方法,脚本创建
  原理是一样的,都是生成密钥和公钥,然后导入密钥
  
页: [1]
查看完整版本: 创建不用ssh密码登陆的docker镜像