docker容器ssh互联

准备

  • Container 1 : Ubuntu 18.04, Name:hadoop01
  • Container 2 : Ubuntu 18.04, Name:hadoop02
  • Net: hadoop-net
sudo docker network create -d bridge hadoop-net
sudo docker run -it --name hadoop01 --network hadoop-net ubuntu:18.04 bash
sudo docker run -it --name hadoop02 --network hadoop-net ubuntu:18.04 bash

安装 ssh

apt install ssh  

配置

  1. 生成密钥对
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
  1. 设置root密码
passwd
  1. 修改sshd_config,添加如下:
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PermitRootLogin yes
  1. 重启sshd
service ssh restart
  1. 传输公钥
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop01
ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop02
  1. 连接测试
ssh hadoop01
ssh hadoop02
# ssh  Ubuntu 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×