300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > linux实现自动互信 Linux 使用shell脚本实现自动SSH互信功能

linux实现自动互信 Linux 使用shell脚本实现自动SSH互信功能

时间:2018-11-28 01:44:16

相关推荐

linux实现自动互信 Linux 使用shell脚本实现自动SSH互信功能

说假设有一个1000台节点的Hadoop集群,要配置节点之间的SSH免密码登录,该如何用shell脚本实现?

#!/bin/expect

#循环1000台机器的IP地址,生成密钥文件authorized_keys

for ip in {cat ip.list}

do

ssh user@$ip ssh-keygen -t rsa &>/dev/null

expect{

"yes/no" { send "yes\r";exp_continue}

"password:"{send "$passwd\r";exp_continue}

}

cat ~/.ssh/id_rsa.pub > ~/.ssh/authorized_keys &> /dev/null

exit

if [ !-f ~/.ssh/authorized_keys ];

then

touch ~/.ssh/authorized_keys

fi

ssh user@$ip cat ~/.ssh/authorized_keys >> ~/.ssh/authorized_keys &> /dev/null

expect{

"yes/no" { send "yes\r";exp_continue}

"password:"{send "$passwd\r";exp_continue}

}

done

#scp authorized_keys 文件到各台机器上面。

for ip in {cat ip.list}

do

scp ~/.ssh/authorized_keys user@$ip:~/.ssh/

expect{

"yes/no" { send "yes\r";exp_continue}

"password:"{send "$passwd\r";exp_continue}

}

done

转载自:/vovlie/archive//09/16/2688020.html

原文:/xibuhaohao/p/11570871.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。