首先去阿里下一个epel源到服务器上
然后yum -y install rsync下载rsync命令的包
设置两台机器互信
#第一台机器
[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:opyF5g1e1nGWVJ6V455lktwOh4yH20mRgECATkXKj8w root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| ++oo..oo..o |
| .o. ..o o= |
| oo . + o* * |
| o.+ . + o @ =|
| E * S * X |
| = O . . = .|
| * . |
| |
| |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id 192.168.100.16
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.100.16's password:
Permission denied, please try again.
root@192.168.100.16's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.100.16'"
and check to make sure that only the key(s) you wanted were added.
#第二台机器
[root@localhost ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Wm2n/SWOarfAbv1domU4tCIh6wzRZAMkb2qp0I+Ok9g root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| ..o |
| o . |
| o + |
| . + + . . |
|. = . o S o o |
|.o o . = + = o |
|oo. o o . =.= = o|
|+oE + ooooO =.|
|... o ooo+o+ .|
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id 192.168.100.15
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.100.15 (192.168.100.15)' can't be established.
ECDSA key fingerprint is SHA256:pSoL7o2TrxRyjd9BkNRsaiefxob8GiBTVkoUgHfVXuk.
ECDSA key fingerprint is MD5:4d:86:96:a1:e7:5f:a8:72:21:8a:0c:ae:48:54:c0:69.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.100.15's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.100.15'"
and check to make sure that only the key(s) you wanted were added.
将ip为192.168.100.16机器上的/etc/目录中的内容拉到本机的/tmp/目录中
rsync -az root@192.168.100.16:/etc/ /tmp/
或者在ip为192.168.100.16执行,将本机的推到192.168.100.16的/tmp/目录下
rsync -az /etc/ root@192.168.100.15:/tmp/
更多参数请使用rsync --help查看