chmod 设置不会设置
我正在尝试 chmod
OS X Lion 中的一个文件夹,
但是当我这样做时,设置似乎没有保留...
users-MacBook-Air:MAMP user$ sudo chmod a=rwx /tmp
users-MacBook-Air:MAMP user$ ls -l /tmp
lrwxr-xr-x@ 1 root wheel 11 Jul 20 23:44 /tmp -> private/tmp
I am trying to chmod
a folder in OS X Lion
However the settings do not seem to stay when I do...
users-MacBook-Air:MAMP user$ sudo chmod a=rwx /tmp
users-MacBook-Air:MAMP user$ ls -l /tmp
lrwxr-xr-x@ 1 root wheel 11 Jul 20 23:44 /tmp -> private/tmp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
lrwxr-xr-x
中的第一个字母l
表示/tmp
是一个 符号链接。这部分
/tmp -> private/tmp
表示它链接到private/tmp
。来自
man chmod
:因此,您可以安全地忽略链接的权限。
请注意,
private/tmp
是相对于/tmp
所在文件夹 -/
的路径。它的绝对路径是/private/tmp
。The first letter
l
inlrwxr-xr-x
means that/tmp
is a symbolic link.This part
/tmp -> private/tmp
means that it links toprivate/tmp
.From
man chmod
:So, you can safely ignore your link's permissions.
Note that
private/tmp
is a path relative to the folder where/tmp
is located -/
. Its absolute path is/private/tmp
.这是因为您正在尝试设置符号链接的权限。那是不可能的。相反,将 chmod 应用于 private/tmp
This is because you are trying to set permissions on a symbolic link. That is not possible. Instead, apply the chmod to private/tmp
在 macOS 上测试。
您可以通过编写
chmod -h 755 file
来更改符号链接的权限。根据chmod
手册,-h
选项更改符号链接的模式,而不是链接指向的文件。如果没有-h
选项,chmod
只会更改符号链接指向的文件的文件模式。请记住检查文件权限是否已成功设置,因为在某些情况下,尽管发出正确的命令,但不会设置符号链接。我不知道导致以下情况的确切过程,但似乎存在某些安全设置,导致符号链接的权限只能在某些用户下进行修改。
如果您不是root用户,您可以通过在
/tmp
文件夹中操作该符号链接来临时修改该符号链接的权限。/tmp
文件夹是一个特殊文件夹,因为它设置了粘滞位。阅读man Sticky
* 了解有关粘性位的更多信息,它甚至列出了/tmp
作为示例文件夹。 root 拥有的任何设置了粘性位的目录都可以工作,但/tmp
是给定计算机上最有可能可用的目录。这很重要,因为作为设置了粘性位的 root 拥有的目录,它允许非 root 用户写入 root 拥有的文件。这意味着,如果您发现当您尝试修改符号链接的权限时,它不断恢复为旧的权限,您可以尝试修改/tmp
中的符号链接的权限,它会保留其新设置的权限。但是,请记住,如果您首先遇到了恢复权限的障碍,那么将文件移回其原始目录将导致权限恢复到它始终恢复到的任何内容。就我而言,它恢复为绝对模式0777
。另外,请记住,符号链接的权限不会影响您访问其链接到的文件的权限,因为这些权限是由该文件本身的权限决定的。*在终端中,输入
man Sticky
并按ENTER
,将显示sticky
的文档。按q
退出。或者,请参阅维基百科上的粘性位。Tested on macOS.
You can change the permissions of the symbolic link by writing
chmod -h 755 file
. From thechmod
manual, the-h
option changes the mode of the symbolic link instead of the file the link points to. Without the-h
option,chmod
would just change the file mode of the file that the symbolic link points to.Keep in mind to check whether or not the file permission was successfully set or not because there are some cases where despite issuing the correct command, the symbolic link will not be set. I do not know the exact process causing the following, but it appears there are certain security settings which cause the permission of the symbolic link to be modifiable only under certain users.
If you are not the root user, you could temporarily modify the permissions of the symbolic link by operating on it in the
/tmp
folder. The/tmp
folder is a special folder because its sticky bit is set. Readman sticky
* to learn more about sticky bits, it even lists/tmp
as an example folder. Any directory owned by root whose sticky bit is set would work, but/tmp
is the directory most likely to be available on a given machine. This matters because as a directory owned by root whose sticky bit is set, it allows non-root users to write to files owned by root. This means that if you find that when you attempt to modify the permissions of a symbolic link it keeps reverting to its old permission, you can attempt to modify the permissions of the symbolic link within/tmp
and it will retain its newly set permissions. However, keep in mind that if you had faced the obstacle of the reverting permissions in the first place, then moving the file back to its original directory would cause the permissions to revert to whatever it always reverts to. In my case it reverted to absolute mode0777
. Also, keep in mind that the permissions of symbolic link do not affect the permissions that you have in accessing the file it links to, since those are determined by the permissions of that file itself.*In the terminal, type
man sticky
and hitENTER
, and documentation forsticky
will be displayed. Pressq
to exit. Alternatively, see Sticky bit on Wikipedia.