【Linux】ssh互信脚本
使用互信脚本的时候,需要敲回车,但是shell脚本无法满足,所以需要用到expect脚本
rpm -qa | grep expect
如果没有的话,直接用yum安装即可
yum install expect -y
我这里以Oracle用户为例
在Oracle的家目录中,【/home/oracle/下】
生成脚本文件autossh.sh和ip.list文件
脚本文件主要内容如下:
#! /usr/bin/expect
spawn ssh-keygen -t rsa
send "\r"
expect "phrase"
send "\r"
expect "again"
send "\r"
interact
set f [open ip.list r]
while { [gets $f ip]>=0} {
spawn ssh-copy-id $ip
expect {
"*yes/no" {send "yes\r";exp_continue}
"*password:" {send "123456\r";exp_continue}
}
}
close $f
spawn ssh-keygen -t dsa
send "\r"
expect "phrase"
send "\r"
expect "again"
send "\r"
interact
set f [open ip.list r]
while { [gets $f ip]>=0} {
spawn ssh-copy-id $ip
expect {
"*yes/no" {send "yes\r";exp_continue}
"*password:" {send "123456\r";exp_continue}
}
}
close $f
保存退出
将ip.list文件中,存放所有想要互相通信的ip
每一个ip占一行
10.0.0.10
10.0.0.11
10.0.0.12
10.0.0.13
expect autossh.sh
完成后,到.ssh下查看是否生成成功
只有学习才能跟上时代的脚步