如何在保留权限的同时在非root用户下运行rsync备份/复制脚本? 这是一个多用户文件服务器,其中每个用户都有一个* nix账户的权限。
使用root用户运行会带来明显的安全风险 – 特别是当您使用无密码的ssh密钥自动执行时。
但是,如果用户不是超级用户(比如对数据目录具有完全组权限的备份用户),则在设置权限时会遇到问题,因为只有所有者或超级用户才能更改权限。
在完美的世界中,生产服务器用户只能拥有只读权限。
谢谢!
你可以使用fakeroot -s:
-s save-file Save the fakeroot environment to save-file on exit. This file can be used to restore the environment later using -i. However, this file will leak and fakeroot will behave in odd ways unless you leave the files touched inside the fakeroot alone when out‐ side the environment. Still, this can be useful. For example, it can be used with rsync(1) to back up and restore whole directory trees complete with user, group and device information without needing to be root. See /usr/share/doc/fakeroot/README.saving for more details.
而是使用不同的帐户,你考虑只允许您的SSH密钥强制命令? 前面我写了关于如何在我的博客上设置rsync的问题。
这意味着ssh密钥只能用于运行你指定的确切的rsync命令,而没有别的。
设置一个备份用户不是我以前看过的,但是我期望它有更多的工作 – 同样,因为这是一个多用户系统,你如何确保所有的文件都是可读的这个用户?
我将在生产系统上configuration一个rsync服务器,以便它可以对生产数据进行只读访问。
像这样的事情将处理:
# cat /etc/rsyncd.conf uid = nobody gid = nobody use chroot = yes max connections = 4 syslog facility = local5 pid file = /var/run/rsyncd.pid [prd_data] path = /path/to/prd_data comment = Production data read only # grep rsync /etc/inetd.conf rsync stream tcp nowait root /usr/bin/rsync rsyncd --daemon # grep rsync /etc/services rsync 873/tcp
然后在备份方面,您可以根据需要configurationfakeroot环境,然后运行:
# rsync -az --delete rsync://prod_server/prd_data /path/to/fakeroot
我的解决scheme是,当rsync需要运行和维护所有权/私有权时,不要将服务器打开到root用户权限,而是从活动服务器上将其推送到备份中,并使用额外机器上的中间暂存区域。
这样做,备份服务器和活动服务器在登台区域都具有SSH访问权限和root权限,但不需要直接进行通信,所以不需要相互访问特权。 登台服务器不需要任何访问就可以连接到现场或备份机器。
这增加了一点复杂性,但意味着你不需要通过SSHlogin特权账户。 它还通过分离添加了一些额外有用的安全性 – 如果确保活动服务器和备份服务器不共享任何凭据,那么如果有人设法侵入(或只是获取/猜测密码)特权帐户直播或备份服务器,他们不能使用访问一个轻松访问另一个。