在不使用 sudo 的情况下每分钟在/var/www 复制文件 [英] To copy files each minute at /var/www without sudo

查看:42
本文介绍了在不使用 sudo 的情况下每分钟在/var/www 复制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有 sudo 的情况下将文件夹复制到/var/www ?

我的文件夹 codes 在/var/www

具有以下权限

4 drwxr-xr-x 8 root root 4096 2009-08-09 03:01 代码

我只能sudo cp -r ~/Dropbox/codes//var/www 复制文件.没有 sudo 我无法复制它们.

解决方案

拥有 /var/www 自己可能会与系统上的其他选项冲突.在我的 Debian 系统上,我会这样做

sudo addgroup wwwsudo adduser nr www # 将自己加入 www 组sudo chgrp -R www/var/www # 在组中制作文件find/var/www -type f -exec chmod g+w '{}' ';'# 使每个文件组可写find/var/www -type d -exec chmod g+ws '{}' ';'# 使每个目录组可写且具有粘性

如果目录是组可写且具有粘性,则在 /var/www 中创建的所有文件都可以被 www 组中的任何人写入,无论是谁或什么创建的他们在那里.(警告:它们必须通过正常"方式创建;cp -a 可以绕过组粘滞位.)

因为 Unix 对组成员资格非常愚蠢,要获得会员资格,您必须重新登录,例如 ssh localhost 或注销并重新登录.麻烦.

How can you copy a folder to /var/www without sudo?

My folder codes has the following permissions at /var/www

4 drwxr-xr-x 8 root root 4096 2009-08-09 03:01 codes

I can only sudo cp -r ~/Dropbox/codes/ /var/www to copy the files. I cannot copy them without sudo.

解决方案

Owning /var/www yourself might conflict with other options on your system. On my Debian system I would do this

sudo addgroup www
sudo adduser nr www   # add myself to the www group
sudo chgrp -R www /var/www  # make files in the group
find /var/www -type f -exec chmod g+w '{}' ';'  # make each file group writable
find /var/www -type d -exec chmod g+ws '{}' ';' # make each directory group writable and sticky

If the directory is group writable and sticky, all files created in /var/www will be writable by anyone in the www group, no matter who or what creates them there. (Caveat: they have to be created by "normal" means; cp -a can circumvent the group sticky bit.)

Because Unix is insanely stupid about group membership, for your membership to be honored you will have to log in again, e.g., ssh localhost or log out and log back in. A nuisance.

这篇关于在不使用 sudo 的情况下每分钟在/var/www 复制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆