配上ssh等效连接
配置等效连接
host1 :192.168.216.150
host2 :192.168.216.151
host3 :192.168.216.152
A.配置 host1 与 host2 的等效连接
步骤1.host1:192.168.216.150
[mysql@host1]$ mkdir ~/.ssh
[mysql@host1]$ chmod 700 ~/.ssh
[mysql@host1]$ ssh-keygen -t rsa
[mysql@host1]$ ssh-keygen -t dsa
步骤2.host2:192.168.216.151
[mysql@host2]$ mkdir ~/.ssh
[mysql@host2]$ chmod 700 ~/.ssh
[mysql@host2]$ ssh-keygen -t rsa
[mysql@host2]$ ssh-keygen -t dsa
步骤3.host1:192.168.216.150
[mysql@host1]$cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[mysql@host1]$cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
[mysql@host1]$ssh 192.168.216.151 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[mysql@host1]$ssh 192.168.216.151 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
[mysql@host1]$scp ~/.ssh/authorized_keys 192.168.216.151:~/.ssh/authorized_keys
步骤4:
[mysql@host1]$ ssh 192.168.216.151 date
[mysql@host2]$ ssh 192.168.216.150 date
B.配置host1与host3的等效连接
1.host3
[mysql@host3]$ mkdir ~/.ssh
[mysql@host3]$ chmod 700 ~/.ssh
[mysql@host3]$ ssh-keygen -t rsa
[mysql@host3]$ ssh-keygen -t dsa
2.host1
[mysql@host1]$ssh 192.168.216.152 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[mysql@host1]$ssh 192.168.216.152 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
[mysql@host1]$scp ~/.ssh/authorized_keys 192.168.216.152:~/.ssh/authorized_keys
B.配置host2与host3的等效连接
host2
[mysql@host1]$ssh 192.168.216.152 cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
[mysql@host1]$ssh 192.168.216.152 cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys
[mysql@host1]$scp ~/.ssh/authorized_keys 192.168.216.152:~/.ssh/authorized_keys
偶尔有些机器上老是配置不成功,非要在root账号下配置。
解决办法(每台机器上root账号下执行):
在ssh用户的
cd /home/mysql/.ssh
chmod 710 authorized_keys
或是修改权限为400
chmod 400 authorized_keys(每台机器执行)