rsync配置免密码验证

1、基于SSH的同步源

可以通过密钥对来实现

客户端:192.168.20.11

[root@server11 /client/rsync]$ ssh-keygen

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

/root/.ssh/id_rsa already exists.

Overwrite (y/n)? y

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:iCvgxpzX0q3f/5zANIrfLtIy1SIdO8CuNFZWRZv4egs root@server11

The key's randomart image is:

+---[RSA 2048]----+

| oo |

| .. o |

| . .. o |

| . * .. |

|. . = S ++ |

|+.. o=.o.*=.. |

| *.o+ooo+Eo+ |

|. .....+oo+ + . |

| ...+o+=.+ |

+----[SHA256]-----+

[root@server11 /client/rsync]$ ssh-copy-id gang@192.168.20.104

/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

gang@192.168.20.104's password:

Number of key(s) added: 1

Now try logging into the machine, with: "ssh 'gang@192.168.20.104'"

and check to make sure that only the key(s) you wanted were added.

[root@server11 /client/rsync]$ ssh 'gang@192.168.20.104'

[gang@server104 ~]$ ifconfig

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500

inet 192.168.20.104 netmask 255.255.255.0 broadcast 192.168.20.255

inet6 fe80::250:56ff:fe21:eabd prefixlen 64 scopeid 0x20<link>

ether 00:50:56:21:ea:bd txqueuelen 1000 (Ethernet)

RX packets 8938 bytes 623153 (608.5 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 4053 bytes 354192 (345.8 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536

inet 127.0.0.1 netmask 255.0.0.0

inet6 ::1 prefixlen 128 scopeid 0x10<host>

loop txqueuelen 1 (Local Loopback)

RX packets 140 bytes 8400 (8.2 KiB)

RX errors 0 dropped 0 overruns 0 frame 0

TX packets 140 bytes 8400 (8.2 KiB)

TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[gang@server104 ~]$ exit

logout

Connection to 192.168.20.104 closed.

[root@server11 /client/ssh]$ rm -rf *

#下行同步

[root@server11 /client/ssh]$ rsync -avz gang@192.168.20.104:/var/www/html/* /client/ssh/

receiving incremental file list

e.txt

index.html

q.txt

w.txt

sent 87 bytes received 247 bytes 668.00 bytes/sec

total size is 8 speedup is 0.02

[root@server11 /client/ssh]$ ll

total 4

-rw-r--r-- 1 gang gang 0 Jan 16 16:34 e.txt

-rw-r--r-- 1 gang gang 8 Jan 16 16:34 index.html

-rw-r--r-- 1 gang gang 0 Jan 16 16:15 q.txt

-rw-r--r-- 1 gang gang 0 Jan 16 16:15 w.txt

2、基于rsync的同步源

#通过系统变量实现 RSYNC_PASSWORD

客户端:192.168.20.11

[root@server11 /client/rsync]$ export RSYNC_PASSWORD=123456

[root@server11 /client/rsync]$ ll

total 8

-rw-r--r-- 1 root root 6 Jan 16 23:15 rsync.txt

-rw-r--r-- 1 root root 0 Jan 16 23:54 zws.txt

-rw-r--r-- 1 root root 3 Jan 16 23:50 zz.txt

[root@server11 /client/rsync]$ rm -rf *

[root@server11 /client/rsync]$ ls

#下行同步

[root@server11 /client/rsync]$ rsync -avz gang@192.168.20.104::share /client/rsync/

receiving incremental file list

./

rsync.txt

zws.txt

zz.txt

sent 115 bytes received 277 bytes 784.00 bytes/sec

total size is 9 speedup is 0.02

#现在执行同步操作不需要输入密码

[root@server11 /client/rsync]$ ll

total 8

-rw-r--r-- 1 root root 6 Jan 16 23:15 rsync.txt

-rw-r--r-- 1 nobody nobody 0 Jan 16 23:54 zws.txt

-rw-r--r-- 1 nobody nobody 3 Jan 16 23:50 zz.txt

#被删除的文件已经从服务端被同步过来了

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值