无需密码通过ssh执行rsync来同步文件(免密码)

一、配置免密码ssh登录

1,使用ssh-keygen生成密匙

# ssh-keygen 
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:
d6:4d:07:4d:30:f5:ec:48:89:59:71:e7:b2:e1:1f:6c root@localhost.localdomain
The key's randomart image is:
+--[ RSA 2048]----+
|            +==.o|
|             *.*.|
|            + * +|
|         . o +.* |
|        S . . +E.|
|       .      ...|
|                .|
|                 |
|                 |
+-----------------+

2,使用ssh-copy-id将公匙拷贝至远程主机

# ssh-copy-id -i /root/.ssh/id_rsa.pub 10.192.23.244
root@10.192.23.244's password: 
Now try logging into the machine, with "ssh '10.192.23.244'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

 

3,测试无需密码通过ssh来执行命令

# ssh 10.192.23.244 date
Thu Jun  8 12:56:46 CST 2017

 

4,rsync执行拉取动作并过滤  (--exclude=必须绝对路径,可以通过--exclude-from文件列表读取)

rsync -az 10.192.23.244:/data0/testdir  --exclude-from=/data0/rsync_exclude/testdir /data0/

 

posted @ 2017-06-08 14:21  wpf926  阅读(130)  评论(0)    收藏  举报