大网数据广告活动
服务器运维问答

Rsync - Setting up rsync user and their permissions

· 52CE 我爱测

I will be setting rsync between two webserver. I am aiming to have backup of data from my primary server on the secoundary in case if primary server crashes. My question relates to setting up on primary server a user account for …

问题原文

原帖链接 · Abdel5 · CC BY-SA 4.0

I will be setting rsync between two webserver. I am aiming to have backup of data from my primary server on the secoundary in case if primary server crashes. My question relates to setting up on primary server a user account for rsync purposes.

For obvious reasons I don't want to use my "root" user account here. Therefore I am aiming at setting up another account which will be used only for rsync purposes. As I understand this user will need read permissions to all files that I will need to transfer (apache configuration, user linux files, www-data).

How to best set up such permissions? Should I grant rsync user root privileges or is there any more secure way to create user for such backup?

已采纳解答

原帖链接 · wurtel · CC BY-SA 3.0

If the network connecting both servers is secure (e.g. a local network at your office) then you can use rsync in daemon mode to connect as root. This way you don't use ssh to make the connection.

On the secondary system, create a file /etc/rsyncd.conf with the following contents:

[all]
  path = /
  read only = no
  uid = 0
  gid = 0
  hosts allow = primary-host
  auth users = backupuser
  secrets files = /etc/rsyncd.secrets
  exclude = /tmp/ /var/tmp/ /var/cache/ /proc/ /sys/ /dev/ /run/ /boot/

Now create a file /etc/rsyncd.secrets with e.g.:

backupuser:thisisasecretpassword

Make the file only readable by root:

# chown root /etc/rsyncd.secrets; chmod 400 /etc/rsyncd.secrets

Now you need to ensure that rsync is started as a daemon; that depends on your distribution, with Debian you edit /etc/default/rsync and change the RSYNC_ENABLE line to RSYNC_ENABLE=true and run /etc/init.d/rsync start (if running systemd then run systemctl enable rsync; systemctl start rsync).

Now you can run rsync on the primary host and send whatever you need to replicate to the secondary by doing e.g.:

# rsync -ai /var/www/ backupuser@secondary-host::all/var/www/

Rsync will ask you for the secret password in this case.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-09-24)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0 / CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。