雞蛋學運維-3:ssh批量管理配置
說明:系統環境CentOS release 6.5 (Final) 2.6.32-431.el6.x86_64
1.添加分發用戶
useradd oldgirl
echo 123456|passwd stdin --oldgirl
2.利用rsync用戶名進行sudo提取cp權限並用-c檢查語法
echo ‘oldgirl ALL=(ALL) NOPASSWD:/usr/bin/rsync‘ >>/etc/sudoers
visudo -c
grep oldgirl /etc/sudoers
3.產生秘鑰對
ssh-keygen -t dsa/rsa
一直回車
ll .ssh/ 查看
4.向客戶端發送公鑰
ssh-copy-id -i .ssh/id_dsa.pub [email protected]
ssh-copy-id -i .ssh/id_dsa.pub [email protected]
ssh-copy-id -i .ssh/id_dsa.pub [email protected]
5.新建分發腳本vim fenfa_good.sh
#!/bin/sh
. /etc/init.d/functions
if [ $# -ne 2 ]
then
echo "USAGE:$0 localfile remotedir"
exit 1
fi
for n in 3 4 5
do
echo " ===============172.16.1.$n============"
scp -p22 -r $1 [email protected]$n:~ &>/dev/null &&\
ssh -t [email protected]$n sudo rsync $1 $2 &>/dev/null
if [ $? -eq 0 ]
then
action "fenfa $1 ok" /bin/true
else
action "fenfa $1 ok" /bin/false
fi
done
雞蛋學運維-3:ssh批量管理配置