rsync的部署我這裏就不講了,本文主要是講怎麼通過用戶名和密碼訪問rsync:
一、rsync服務端安全配置
1、創建密碼文件並修改權限
touch /etc/rsync.pass
內容爲root:123456
修改/etc/rsync.pass權限爲600
chmod 600 /etc/rsync.pass
2、修改rsync的配置文件/etc/rsyncd.conf
增加以下兩行內容:
secrets file = /etc/rsync.pass
auth users = root
配置文件全部內容如下:
uid = root
pid file=/var/run/rsyncd.pid
log file=/var/log/rsyncd.log
secrets file = /etc/rsync.pass
auth users = root
[temp]
path = /data0
read only = no
3、重啓rsync進程
kill掉rsync進程:
ps -aux | grep rsync
kill -9 ${pid}
啓動rsync進程:
rsync --daemon
二、rsync客戶端安全訪問方式
1、手動輸入密碼
rsync [email protected]::temp/yarn-site.xml .
Password:
2、創建密碼文件,配置項指定密碼文件
rsync [email protected]::temp/yarn-site.xml . --password-file=rsync.pass
其中rsync.pass只有密碼123456,用戶名在命令行已經指定,rsync.pass文件的權限改成6003、export環境變量,免密碼rsync
export RSYNC_PASSWORD=${pass}
設置了環境變量RSYNC_PASSWORD之後,就可以免密碼使用rsync了:
rsync [email protected]::temp/yarn-site.xml .
以下是環境變量RSYNC_PASSWORD的說明:
RSYNC_PASSWORD
Setting RSYNC_PASSWORD to the required password allows you to run
authenticated rsync connections to an rsync dae-mon without user
intervention. Note that this does not supply a password to a shell transport such as ssh.