SSH远程登陆docker容器
[sudo] hsl 的密码:
REPOSITORY TAG IMAGE ID CREATED SIZE
hsl/ubuntu 14.04_add_sourcealiyun_git_vim_ssh 7e81fb2f82c5 44 minutes ago 634.2 MB
hsl/ubuntu 14.04_JenkinsWithDocker_key 6fb1d3cb7983 46 hours ago 760 MB
hsl/ubuntu 14.04_JenkinsWithDocker_password 659fcb00b0dc 3 days ago 760.1 MB
ubuntu 14.04 4a725d3b3b1c 8 days ago 188 MB
training/webapp latest 6fae60ef3446 15 months ago 348.8 MB
hsl@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
hsl@ubuntu:~$ sudo docker run -tid -p 22 -P hsl/ubuntu:14.04_add_sourcealiyun_git_vim_ssh
ea153153c8837a4b0e1a8d0e6945200c7ac820c358d546202f1a95c72f12ca77
hsl@ubuntu:~$ sudo docker exec -ti ea /bin/bash
root@ea153153c883:/# cd /etc/ssh
root@ea153153c883:/etc/ssh# vim sshd_config
root@ea153153c883:~# service ssh start
* Starting OpenBSD Secure Shell server sshd [ OK ]
root@ea153153c883:/# passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@ea153153c883:/# ifconfig
root@ea153153c883:/# exit
exit
hsl@ubuntu:~$ ssh root@172.17.0.2
root@172.17.0.2's password:
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.0-93-generic x86_64)
* Documentation: https://help.ubuntu.com/
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
root@ea153153c883:~# exit
logout
Connection to 172.17.0.2 closed.
hsl@ubuntu:~$ ifconfig
hsl@ubuntu:~$ ssh -p 32771 root@192.168.127.159
The authenticity of host '[192.168.127.159]:32771 ([192.168.127.159]:32771)' can't be established.
ECDSA key fingerprint is SHA256:icDOU4lcWTiFb4eIKUtosFNrqzGMo5ufzqXQfPdtSZg.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.127.159]:32771' (ECDSA) to the list of known hosts.
root@192.168.127.159's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-36-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Sun Sep 4 06:00:37 2016 from 172.17.0.1
root@ea153153c883:~# exit
logout
Connection to 192.168.127.159 closed.
hsl@ubuntu:~$ ssh -p 32771 root@192.168.127.159
root@192.168.127.159's password:
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-36-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Sun Sep 4 06:01:33 2016 from 192.168.127.159
root@ea153153c883:~# exit
logout
Connection to 192.168.127.159 closed.
hsl@ubuntu:~$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f2e54200c5c7 hsl/ubuntu:14.04_add_sourcealiyun_git_vim_ssh "/bin/bash" 15 seconds ago Up 10 seconds 0.0.0.0:32768->22/tcp big_brown
hsl@ubuntu:~$ sudo docker exec -it f2 /bin/bash
root@f2e54200c5c7:/# vim /etc/ssh/sshd_config
exit
#一直回车,生成宿主机的密钥
hsl@ubuntu:~$ cd .ssh
hsl@ubuntu:~/.ssh$ ls
id_rsa id_rsa.pub
root@172.17.0.2's password:
id_rsa.pub 100% 392 0.4KB/s 00:00
hsl@ubuntu:~/.ssh$ sudo docker exec -it f2 /bin/bash
root@ea153153c883:/# cd
root@ea153153c883:~# cd .ssh
root@ea153153c883:~/.ssh# ls
id_rsa.pub
root@ea153153c883:~/.ssh# mv id_rsa.pub authorized_keys
root@ea153153c883:~/.ssh# ls
authorized_keys
hsl@ubuntu:~/.ssh$ ls
id_rsa id_rsa.pub known_hosts
hsl@ubuntu:~/.ssh$ cat id_rsa.pub
#宿主机的公钥
hsl@ubuntu:~/.ssh$ sudo docker exec -it f2 /bin/bash
root@f2e54200c5c7:/# ssh-keygen -t rsa
#这一步只是为了方便产生docker的.ssh目录
root@f2e54200c5c7:/# cd
root@f2e54200c5c7:~# cd .ssh
root@f2e54200c5c7:~/.ssh# ls
id_rsa id_rsa.pub
root@f2e54200c5c7:~/.ssh# touch authorized_keys
root@f2e54200c5c7:~/.ssh# ls
authorized_keys id_rsa id_rsa.pub
root@f2e54200c5c7:~/.ssh# vim authorized_keys
#把宿主机的id_rsa.pub内容复制到docker的/root/.ssh/authorized_keys
root@f2e54200c5c7:/# service ssh start
* Starting OpenBSD Secure Shell server sshd [ OK ]
root@f2e54200c5c7:/# exit
exit
hsl@ubuntu:~/.ssh$ ssh root@172.17.0.2
Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-36-generic x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Sun Sep 4 08:18:21 2016 from 172.17.0.1
root@f2e54200c5c7:~# exit
logout
Connection to 172.17.0.2 closed.
SSH远程登陆docker容器的更多相关文章
- pycharm远程调试docker容器内程序
文章链接: https://blog.csdn.net/hanchaobiao/article/details/84069299 参考链接: https://blog.csdn.net/github_ ...
- 创建支持ssh服务的docker容器和镜像
http://www.kongxx.info/blog/?p=57 1. 这里使用的centos作为容器,所以首先下载centos的imagessudo docker pull centos 2. 下 ...
- ssh远程连接docker中linux(ubuntu/centos)
ssh远程连接docker中linux(ubuntu/centos) https://www.jianshu.com/p/9e4d50ddc57e centos docker pull centos: ...
- ssh远程连接docker中的 linux container
ssh远程连接docker中的container 由于工作需要,要远程连接Container,本地机器是windows,以下为解决步骤: 1. 环境 本地:Windows ↓ Docker版本1. ...
- linux系统新建用户ssh远程登陆显示-bash-4.1$解决方法
linux系统新建的用户用ssh远程登陆显示-bash-4.1$,不显示用户名路径 网络上好多解决办法,大多是新建.bash_profile文件然后输入XXXXX....然而并没有什么用没有用.... ...
- CentOS6无法本地登陆,ssh远程登陆没问题
CentOS6无法本地登陆,ssh远程登陆没问题---使用CentOS自带的rsyslog分析调试 Apr 21 14:15:27 raccontroller init: tty (/dev/tty1 ...
- 树莓派3b+ Ubuntu 16.04 MATA系统 ssh远程登陆后修改主机名、用户密码和用户名
写在前面: 刚刚开始写博客,记录下自己的学习过程,备忘. 最近在使用树莓派做智能小车的开发,使用的是树莓派3b+,安装的是Ubuntu 16.04 MATA 系统,安装系统后需要修改主机名,登陆密码以 ...
- SSH 远程登陆
2019-03-10 20:41:39 一.什么是SSH 简单说,SSH是一种网络协议,用于计算机之间的加密登录. 如果一个用户从本地计算机,使用SSH协议登录另一台远程计算机,我们就可以认为,这种登 ...
- Linux服务器开启ssh服务,实现ssh远程登陆!
最近在学linux,使用ssh远程登陆linux,记录下来! 首先进入/etc目录下,/etc目录存放的是一些配置文件,比如passwd等配置文件,要想使用ssh远程登陆,需要配置/etc/ssh/s ...
随机推荐
- [Oracle] - Install Oracle12cR1 on Oracle Linux 6.5 in VirtualBox
My Oralce Linux 6.5 is running on VirtualBox. Basic settings is 4G memory, 50G hard-disk, auto parti ...
- jQuery读取json文件
转 http://www.jb51.net/article/36678.htm 1.userInfo.html <!DOCTYPE html PUBLIC "-//W3C//DTD X ...
- TPM Key相关概念
1. Storage Keys:存储密钥,用来加密数据和其它密钥的通用非对称密钥,这里的其它密钥可以是另外一个存储密钥,也可以是绑定密钥或签名密钥.它本身是长度2048bit的RSA私钥:它既可以是可 ...
- C++标准库之condition_variable
conditon_variable(条件变量)用于线程间同步 condition_variable有5个函数,函数名及对应的功能如下: wait阻塞自己,等待唤醒 wait_for阻塞自己,等待唤醒, ...
- HTTPS请求 SSL证书验证
import urllib2 url = "https://www.12306.cn/mormhweb/" headers = {"User-Agent": & ...
- jQuery + Cookie引导客户操作
网址:http://www.sucaihuo.com/js/707.html 示例:http://www.sucaihuo.com/jquery/7/707/demo/
- Wireshark使用注意事项
一直在使用老板的Wireshark,因为4G网络的逐步开通,越来越须要新版Wireshark来解析一些数据包. 在更换了新Wireshark的1.11.3后发现原来能够解析Gb口数据的NSIP不见了 ...
- hdu5125(LIS)
相当于用多个O(nlog(n))LIS来做. // // main.cpp // 160322 // // Created by 陈加寿 on 16/3/22. // Copyright © 2016 ...
- sql server 2008 对字段的操作
添加,刪除字段 通用式: alter table [表名] add [字段名] 字段属性 default 缺省值 default 是可选参数 增加字段: 增加数字字段,整型,缺省值为0 增加数字 ...
- 【BZOJ3998】[TJOI2015]弦论 后缀自动机
[BZOJ3998][TJOI2015]弦论 Description 对于一个给定长度为N的字符串,求它的第K小子串是什么. Input 第一行是一个仅由小写英文字母构成的字符串S 第二行为两个整数T ...