docker ssh

1,首先,需要从Docker官网获得centos或Ubuntu镜像


2,当本地已有Ubuntu镜像后(大概200M左右大小),使用如下命令

[cpp]   view plain  copy
  1. docker run -t -i ubuntu /bin/bash  
即可启动一个容器,并放入Ubuntu镜像

3,更新源, apt-get update

接着就可以使用 apt-get install openssh-client openssh-server 来安装openssh服务了

需要把此镜像保存一下:

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. docker commit [container-id] [image-id]  
在把刚刚的container干掉:

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. docker stop [container-id]  
嗯,还需要将这个container删除掉

[csharp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. docker rm [container-id]  

最后,加载刚刚保存到的最新的image,放入到新的容器中去:

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. docker run --name [image-name] -i -t -p 50001:22 [image-id]  


4,启动openssh服务

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. /etc/init.d/ssh start  

5,此时可以从其他机器登陆到这个docker容器里了


6,可能出现一些错误使得一登陆进去就直接关闭连接了:

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. [root@Wshare84 start_docker_sh]# ssh root@10.10.2.84 -p 50001  
  2. The authenticity of host '[10.10.2.84]:50001 ([10.10.2.84]:50001)' can't be established.  
  3. RSA key fingerprint is aa:05:84:4c:f2:15:f3:04:89:9c:04:33:0d:15:14:1f.  
  4. Are you sure you want to continue connecting (yes/no)? yes  
  5. Warning: Permanently added '[10.10.2.84]:50001' (RSA) to the list of known hosts.  
  6. root@10.10.2.84's password:   
  7. Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 2.6.32-431.el6.x86_64 x86_64)  
  8.   
  9.  * Documentation:  https://help.ubuntu.com/  
  10. Last login: Wed Jan 21 01:25:17 2015 from 172.17.42.1  
  11. Connection to 10.10.2.84 closed.  

此时解决方案:

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key  
  2. ssh-keygen -t rsa -f  /etc/ssh/ssh_host_rsa_key  

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. echo 'root:yourpasswd' | chpasswd //设置root密码  

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. vi  /etc/ssh/sshd_config   
将PermitRootLogin 改为 yes,将 UsePAM  改为 no。

重启服务:

[cpp]   view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. /etc/init.d/ssh restart  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值