标签: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 oldgir@172.16.1.3
ssh-copy-id -i .ssh/id_dsa.pub oldgir@172.16.1.4
ssh-copy-id -i .ssh/id_dsa.pub oldgir@172.16.1.5
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 oldgirl@172.16.1.$n:~ &>/dev/null &&\
ssh -t oldgirl@172.16.1.$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
标签:ssh
原文地址:http://78124107.blog.51cto.com/5557978/1971183