比如我們有一個服務器,想把各個機器的文件都通過腳本傳給這臺機,用sftp或者直接rsync就必須輸密碼,肯定不行,做等效性免密又麻煩,怎么辦呢,這么辦!
在服務端
yum -y install rsync
#編輯,內容如下
vim /etc/rsyncd.conf
uid = user1 #決定了寫入到服務端的文件的屬主
gid = user1 #決定了寫入到服務端的文件的屬組
[backup]: path = /var/nfs #路徑自定義read only = false #允許寫入fake super = yes #沒有這一行會提示無權限修改文件auth users = guest1 #客戶端要訪問用的用戶名,沒有這一行則無需密碼secrets file = /etc/rsyncd.secrets #密碼文件
其中密碼文件就是 guest1:xxxxxxxxxxx
然后 service rsync start
在客戶端
vim /etc/rsync.passwd #內容就是密碼 xxxxxxxxxxxx
#然后
chmod 640 /etc/rsync.passwd
rsync -avzo demo.txt guest1@server_ip::backup/demo1.txt --password-file=/etc/rsync.passwd
即可