记录一则Linux SSH的互信配置过程

需求:四台Linux主机,IP地址为192.168.10.10/11/12/13,配置登录用户的互信

1.各节点ssh-keygen生成RSA密钥和公钥

ssh-keygen -q -t rsa  -N "" -f  ~/.ssh/id_rsa

2.将所有的公钥文件汇总到一个总的授权key文件中

在10执行汇总:

ssh 192.168.10.10 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh 192.168.10.11 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh 192.168.10.12 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
ssh 192.168.10.13 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

出于安全性考虑,将这个授权key文件赋予600权限:

chmod 600 ~/.ssh/authorized_keys

3.将这个包含了所有互信机器认证key的认证文件,分发到各个机器中去

scp ~/.ssh/authorized_keys  192.168.10.11:~/.ssh/
scp ~/.ssh/authorized_keys  192.168.10.12:~/.ssh/
scp ~/.ssh/authorized_keys  192.168.10.13:~/.ssh/

4.验证互信,各节点执行下面命令,能不输入密码显示时间,配置成功

ssh 192.168.10.10 date;ssh 192.168.10.11 date;ssh 192.168.10.12 date;ssh 192.168.10.13 date;

5.配置完互信,借用之前同事写的一个实用小脚本,在10上建立,以便于集群间快速同步统一的配置文件

vi bulkcp.sh
#!/bin/bash
for((i=11;i<=13;i++))
do
scp -r $1 192.168.10.$i:$2
echo scp -r $1 192.168.10.$i:$2
done

./bulkcp.sh /etc/hosts /etc/hosts
This entry was posted in Linux and tagged , . Bookmark the permalink.