[root@m01 ~]# visudo
oldgirl ALL= NOPASSWD: /usr/bin/rsync
末尾添加
配置suduer:nfs,backup,web
echo "oldgirl ALL= NOPASSWD: /usr/bin/rsync " >>/etc/sudoers
visudo -c
把要操作的考到当前目录
[root@m01 ~]# su - oldgirl #<==要在用户下,否则需要密码
[oldgirl@m01 ~]$ cp /etc/hosts .
[oldgirl@m01 ~]$ scp -P52113 hosts oldgirl@172.16.1.31:~
hosts 100% 331 0.3KB/s 00:00
[oldgirl@m01 ~]$
[oldgirl@nfs01 ~]$ ll
total 4
-rw-r--r-- 1 oldgirl oldgirl 331 Feb 12 23:01 hosts
[oldgirl@nfs01 ~]$
远程sudo
ssh -p52113 -t oldgirl@172.16.1.31 sudo rsync ~/hosts /etc/hosts
[root@m01 ~]# su -
[root@m01 ~]# su - oldgirl
[oldgirl@m01 ~]$ scp hosts oldgirl@172.16.1.8:~
hosts 100% 358 0.4KB/s 00:00
[oldgirl@m01 ~]$ ssh oldgirl@172.16.1.8 sudo rsync ~/hosts /etc/hosts
[oldgirl@m01 ~]$
[root@web01 /]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.5 lb01
172.16.1.6 lb02
172.16.1.7 web02
172.16.1.8 web01
172.16.1.51 db01 db01.etiantian.org
172.16.1.31 nfs01
172.16.1.41 backup
172.16.1.61 m01
[root@web01 /]# cat /home/oldgril/hosts
cat: /home/oldgril/hosts: No such file or directory
[root@web01 /]# cat /home/oldgirl/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.5 lb01
172.16.1.6 lb02
172.16.1.7 web02
172.16.1.8 web01
172.16.1.51 db01 db01.etiantian.org
172.16.1.31 nfs01
172.16.1.41 backup
172.16.1.61 m01
172.16.1.31 nfs01
#############20200212#####
[root@web01 /]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.1.5 lb01
172.16.1.6 lb02
172.16.1.7 web02
172.16.1.8 web01
172.16.1.51 db01 db01.etiantian.org
172.16.1.31 nfs01
172.16.1.41 backup
172.16.1.61 m01
172.16.1.31 nfs01
#############20200212#####
[root@web01 /]#