如何在没有sudo的情况下将文件夹复制到/ var/www?
我的文件夹codes在/ var/www具有以下权限
4 drwxr-xr-x 8 root root 4096 2009-08-09 03:01 codes
Run Code Online (Sandbox Code Playgroud)
我只能sudo cp -r ~/Dropbox/codes/ /var/www复制文件.没有sudo,我无法复制它们.
拥有/var/www自己可能会与您系统上的其他选项发生冲突.在我的Debian系统上,我会这样做
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
Run Code Online (Sandbox Code Playgroud)
如果目录是组可写和粘滞的,则创建的所有文件/var/www将由www组中的任何人写入,无论是谁或在那里创建它们.(警告:他们必须通过"正常"手段创建; cp -a可以绕过群体粘性位.)
因为Unix对于团体会员资格非常愚蠢,为了使您的会员资格得到尊重,您将不得不再次登录,例如,ssh localhost或者注销并重新登录.令人讨厌.