简体   繁体   English

允许 www-data 在其他用户下执行 rsync (php)

[英]Allow www-data to execute rsync under other user (php)

I would like to allow php to perform rsync under an other users's privileges, let's say wwwsync user.我想允许 php 在其他用户的权限下执行 rsync,比如说 wwwsync 用户。

How can I acheive this with sudo configuration?我怎样才能通过 sudo 配置来实现这一点? Here is what I have done :这是我所做的:

In sudo configutaion (sudo visudo)在 sudo configutaion (sudo visudo)

www-data www-data-sync=(wwwsync) NOPASSWD: /usr/bin/rsync

This line works as excpected when logged as wwwsync user当以 wwwsync 用户身份登录时,此行按预期工作

rsync -avz -e "ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress ~/some/path/ [remoteuser]@[remotehost]:~/some/path/

But this line executed from php using shell_exec() does not work但是使用shell_exec()从 php 执行的这一行不起作用

sudo -u wwwsync rsync -avz -e "ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress ~/some/path/ [remoteuser]@[remotehost]:~/some/path/

Is it the right way to execute rsync under wwwsync user?这是在 wwwsync 用户下执行 rsync 的正确方法吗? Is the sudo configuration set properly? sudo 配置设置是否正确?

I finally found out how to make it work.我终于知道如何让它工作了。

sudoer configuration was wrong. sudoer 配置错误。 Alias must be ALL, not a random alias.Also, "rsync" must have "-H" option set so the command sets the target home folder as home folder while command is executed.别名必须是 ALL,而不是随机别名。此外,“rsync”必须设置“-H”选项,以便该命令在执行命令时将目标主文件夹设置为主文件夹。

In sudo configuration (sudo visudo)在 sudo 配置中 (sudo visudo)

www-data ALL=(wwwsync) NOPASSWD: /usr/bin/rsync

This line executed from php using shell_exec() does work (with ssh key properly set for user wwwsync and remote host)使用 shell_exec() 从 php 执行的这一行确实有效(为用户 wwwsync 和远程主机正确设置了 ssh 密钥)

sudo -H -u wwwsync rsync -avz -e "ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /some/path/ [remoteuser]@[remotehost]:~/some/path/

Note : wwwsync rigths / perms must be carfully set so www-data won't synchronize unwanted folders to remote host.注意: wwwsync rigths / perms 必须仔细设置,以便 www-data 不会将不需要的文件夹同步到远程主机。

This finally allows me to perform safe ressource synchronisation between a master server and slave servers : Safe way to synchronize ressources between servers through php / linux这最终允许我在主服务器和从服务器之间执行安全的资源同步: 通过 php / linux 在服务器之间同步资源的安全方法

If that could help...如果那可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM