本文是为了docker-machine增加现有虚拟机服务器为节点而做
docker-machine create -d generic --generic-ip-address=192.168.102.128 --generic-ssh-user=hbd 128
新增用户hbd
useradd -d /home/hbd -s /bin/bash -m hbd passwd hbd
1、设置/etc/hosts
128机器
192.168.102.128 centos128 192.168.102.129 centos129 192.168.102.128 localhost
129机器
192.168.102.128 centos128 192.168.102.129 centos129 192.168.102.129 localhost
2、设置主机名
128机器
hostname centos128
129机器
hostname centos129
3、修改ssh config配置,vim /etc/ssh/sshd_config 将下面两个参数#注释放开
RSAAuthentication yes
PubkeyAuthentication yes
4、生成秘钥
使用hbd用户登录两台服务器,
在home/hbd目录下创建文件夹”.ssh",
cd到.ssh文件夹,输入命令“ssh-keygen -t rsa",回车到底
完成后会生成两个证书文件
[test@centos128 .ssh]$ ls id_rsa id_rsa.pub
5、合并id_rsa.pub,追加到authorized_key文件中
hbd登录centos128, 在“.ssh”文件夹下,输入命令“scp id_rsa.pub hbd@centos129:~/.ssh/authorized_keys”,拷贝128的公钥id_rsa.pub到129的.ssh/authorized_keys。
hbd登录centos129,在“.ssh”文件夹下,输入命令“cat id_rsa.pub >> authorized.keys”,把129的公钥id_rsa.pub追加到129的authorized_keys文件。查看文件“authorized_keys”,内容如下:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDj0xgwDV/1a8m5enIC4Aqj2VHzpay+P68KzCIEF+rW0V5FhpzBX90AuFNVTitw/qzvrw9v89w8jPdshgzXTxjfnT9DIdHWlWqFXgQYsfp9c+VdO4tCMidtw6dPMNHs95sKW7iIcuRuh66T1evCP+ZxlgE9n4VAC9gQXWsMUzC9bHe62duUygwBTDG4mCKSkCiOSNNGlGimqLb+TWDbaUPcirM2r9NbQVAQDs+fFKZz8SWHlTHSBN7IH3KFYuXnyJ7P41FhXMUYLklCLRaGvqcul3wJ7BiSbq+fVWXONpc2r0BwkbcdgV8MBxMZFFmVu3sSOBILepxsTTrv+wTtX3cR hbd@centos128 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7b73IJej9kwX2QT/TJhf5waKT+XB997BiRzhRPbXeF2AX0f2oNOH2UU3+kcfZErLfUWzanZzeD/s0gpC/S1QzV+6jPC5IJ7w44HrXkWPoQYnAFXVuTZlZGdHomI8UPOecRMeQMEgIxwCMR19Kket9YKXxAs6SwKMLPZRlbNc6KLAkbF0NSyoaUqp3mHIOAzpR3CoutRPdU0UDQ27cV8Hi29Q1yTrw0cDsQsmo0wFMqd6EcBB+MngSGxs2pXpTXS5PTseRs8ohtfVJMAe+vkZc47DsTBGYStQnYJ/rDm2QTIs+VjCAJfhYwH5Xi9HJQ5S7244Lngw+WeH7W2orJ9tr hbd@centos129
在129的“.ssh”文件夹下,复制authorized_keys到128的hbd,命令“scp authorized_keys hbd@128:~/.ssh/",此时,128、129两台服务器的authorized_keys一致
6、测试登录
在128,hbd用户登录的情况下,输入“ssh hbd@centos129”
在129,hbd用户登录的情况下,输入“ssh hbd@centos128”
如在ssh登入时需要输入密码,需要需改.ssh文件夹访问权限,分配权限为登陆用户
chmod 700 /home/hbd/.ssh
chmod 600 /home/hbd/.ssh/*
chown hbd: /home/hbd/.ssh
chown hbd: /home/hbd/.ssh/*
然后各个客户机好似要重启才能生效。