`chmod -R ugo+rwx /` 比 `chmod -R 777 /` 危险性低吗?

`chmod -R ugo+rwx /` 比 `chmod -R 777 /` 危险性低吗?

我读这里chmod -R 777 /是一个非常坏主意,因为它会覆盖文件的权限并停用setuidsetgid和粘滞位。

然而,我认为这chmod -R ugo+rwx /不会覆盖权限,而是添加它们(如果没有),因此它比上述命令安全得多。如果我没记错的话,它也不会关闭任何特殊位。

我对吗?或者这些命令基本上相同并且都会破坏我的系统?

我无意这样做,只是要求一般文化。

答案1

您将剥夺系统的所有安全性,使其极易受到攻击。由于权限不安全,许多程序将停止运行。从技术上讲,您是对的,它会附加这些而不是覆盖写入,因此您将保留 SGID 和 SUID 权限。我有一台不再需要的旧 Ubuntu 机器,所以我想我应该测试一下。运行后chmod -R ugo+rwx / sudo由于不安全的权限而停止工作/usr/lib/sudo/sudoers.sossh停止工作,因为我使用 rsa 密钥,这也需要严格的权限。我无法在操作系统中重新启动机器,因为机器sudo已损坏,但电源按钮工作正常。我很惊讶,因为服务器实际上启动得很好,我可能可以用单用户模式修复它,但我只是要重新安装。所以回答你的问题,不。虽然chmod -R ugo+rwx /在技术上有所不同,但chmod -R 777 /它并不安全,因为它们都会破坏您的系统。

答案2

我认为这些命令不一样,因为您使用的是+符号表示而不是=,因此您的观察可能是正确的,但最好查看 chmod 的手册页。man chmod

......................

 SETUID AND SETGID BITS
   chmod clears the set-group-ID bit of a regular file if the file's group ID does not match
   the  user's  effective  group ID or one of the user's supplementary group IDs, unless the
   user has appropriate privileges.  Additional restrictions may cause the  set-user-ID  and
   set-group-ID  bits  of  MODE or RFILE to be ignored.  This behavior depends on the policy
   and functionality of the underlying chmod system call.  When in doubt, check the underly‐
   ing system behavior.

   chmod  preserves  a  directory's  set-user-ID and set-group-ID bits unless you explicitly
   specify otherwise.  You can set or clear the bits with symbolic modes like u+s  and  g-s,
   and you can set (but not clear) the bits with a numeric mode.

相关内容