首页 > 代码库 > 运用sshpass及脚本实现批量建立信任关系
运用sshpass及脚本实现批量建立信任关系
1、http://sourceforge.net/projects/sshpass/
2、
#cd sshpass-1.05/
3.
#./configure && make && make install
4.
#sshpass -p aixocm ssh 192.168.199.129直接登录
5.
#sshpass -p aixocm scp sshpass-1.05.tar.gz 192.168.199.129:/lianxi
6、脚本实现批量建立单向信任
#vim /shell/sshpass.sh
IP=`cat ip_list.txt`
error_check()
echo "$1 error" >error.log
exit
fi
}
create()
{
IP=`cat ip_list.txt`
PASS=`cat passwd.txt`
#####error check##########
error_check()
{
if (( $? != 0 ));then
echo "$1 error" >error.log
exit
fi
}
create()
{
for i in $IP
do
sshpass -p $PASS ssh $i useradd liu
error_check Adduser
sshpass -p $PASS ssh $i mkdir /home/liu/.ssh
error_check directory_create
sshpass -p $PASS ssh $i chmod 700 /home/liu/.ssh
error_check permissions
sshpass -p $PASS ssh $i chown liu:liu /home/liu/.ssh
error_check owner
sshpass -p $PASS scp /home/liu/.ssh/authorized_keys $i:/home/liu/.ssh
error_check scp_use
sshpass -p $PASS ssh $i chmod 600 /home/liu/.ssh/authorized_keys
error_check chown600
sshpass -p $PASS ssh $i chown liu:liu /home/liu/.ssh/authorized_keys
error_check chownliu
echo "与$i的单向关系已经建立"
done
}
create
本文出自 “流浪滴流氓” 博客,转载请与作者联系!
运用sshpass及脚本实现批量建立信任关系