关于tensorflow:mac下ssh连接docker的方法

3次阅读

共计 938 个字符,预计需要花费 3 分钟才能阅读完成。

1、进入 docker 中的 linux 须要装置 ssh 服务

apt-get update
apt-get install openssh-server openssh-client

2、设置 docker 的 root 登录权限为 yes

批改 /etc/ssh/sshd_config 文件,找到 PermitRootLogin,参数批改为 yes

vim /etc/ssh/sshd_config

3、批改 docker 的 root 明码

应用 passwd root 命令批改 root 登录明码

passwd root

4、确认 docker 中密匙是否存在,没有则须要创立

如下是不存在密匙

root@c223a9d1c7a0:/home# ll /etc/ssh
total 560
drwxr-xr-x 1 root root   4096 Oct 10 03:29 ./
drwxr-xr-x 1 root root   4096 Oct 10 03:32 ../
-rw-r--r-- 1 root root 553122 Feb 10  2018 moduli
-rw-r--r-- 1 root root   1580 Feb 10  2018 ssh_config
-rw-r--r-- 1 root root   3800 Oct 10 03:29 sshd_config

生成主秘密匙(执行如下命令时能够一路回车):

  1. 生成 rsa_key (- t 示意生成的密钥所应用的加密类型;- f 项后接要生成的密钥文件名)
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
  1. 生成 ecdsa_key
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key
  1. 生成 ed25519_key。
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key

5、退出容器

exit 命令退出容器

6、提交这个 container 为一个新的 image

docker commit < 容器 id> < 镜像名称 >

7、应用新的镜像启动一个指定了 ip 映射的新容器

把容器的 22 端口映射到虚拟机的 8122 端口

docker run --name < 容器名称 > -i -t -p 8122:22 < 镜像 ID> /usr/sbin/sshd -D

8、在主机 ssh 登录 docker

ssh root@localhost -p 8122

一生学习!

正文完
 0