linux用户的根目录
Most of the time, none of us willingly performs an action that will literally break our operating systems and force us to reinstall them. But what if such an action could easily occur even by accident on the user’s part? Today’s SuperUser Q&A post has the answer to a confused reader’s question.
在大多数情况下,我们没人愿意执行会破坏操作系统并强迫我们重新安装它们的操作。 但是,如果即使是用户意外,也很容易发生这种动作怎么办? 今天的“超级用户问答”帖子回答了一个困惑的读者的问题。
Today’s Question & Answer session comes to us courtesy of SuperUser—a subdivision of Stack Exchange, a community-driven grouping of Q&A web sites.
今天的“问答”环节由SuperUser提供,它是Stack Exchange的一个分支,该社区是由社区驱动的Q&A网站分组。
问题 (The Question)
SuperUser reader fangxing wants to know why Linux would allow users to remove the root directory:
超级用户阅读者fangxing想知道为什么Linux允许用户删除根目录:
When I installed Linux on my computer for the first time, I always liked to use root because I did not need to add sudo and enter my password every time I executed a command that needed root level permissions.
第一次在计算机上安装Linux时,我总是喜欢使用root,因为不需要每次执行需要root级权限的命令时都添加sudo并输入密码。
One day, I just wanted to remove a directory and ran rm -rf /, which “broke” my system. I have been wondering why Linux’s designers did not block such a dangerous command from being run so easily.
有一天,我只想删除一个目录并运行rm -rf / ,它“破坏了”我的系统。 我一直在想,为什么Linux的设计人员没有阻止这么危险的命令这么容易地运行。
Why does Linux allow users to remove the root directory?
为什么Linux允许用户删除根目录?
答案 (The Answer)
SuperUser contributor Ben N has the answer for us:
超级用户贡献者Ben N为我们提供了答案:
Why should it block you from doing whatever you want with your own computer? Logging in as root or using sudo is literally saying to the machine, “I know what I am doing.” Preventing people from doing dubious things usually also prevents them from doing clever things (as expressed by Raymond Chen).
为什么要阻止您使用自己的计算机执行任何操作? 从根本上登录或使用sudo对机器说:“我知道我在做什么。” 阻止人们做可疑的事情通常也会阻止他们做聪明的事情(如雷蒙德·陈表示)。
Besides, there is one singularly good reason to allow a user to torch the root directory: decommissioning a computer by completely erasing the operating system and file system. (Danger! On some UEFI systems, rm -rf / can brick the physical machine too.) It is also a reasonable thing to do inside a chroot jail.
此外,有一个奇特的理由让用户可以破坏根目录:通过完全擦除操作系统和文件系统来停用计算机。 (危险!在某些UEFI系统上, rm -rf /也会使物理机变砖。)在chroot监狱中进行操作也是合理的。
Apparently, people accidentally ran the command so much that a safety feature was added. rm -rf / does nothing on most systems unless –no-preserve-root is also supplied, and there is no way that you can type that by accident. That also helps guard against poorly-written but well-intentioned shell scripts.
显然,人们不小心运行了命令,以至于添加了安全功能。 rm -rf /在大多数系统上不执行任何操作,除非还提供了–no-preserve-root ,并且您不可能无意间输入该内容。 这也有助于防止编写不良但意图良好的shell脚本。
Have something to add to the explanation? Sound off in the comments. Want to read more answers from other tech-savvy Stack Exchange users? Check out the full discussion thread here.
有什么补充说明吗? 在评论中听起来不错。 是否想从其他精通Stack Exchange的用户那里获得更多答案? 在此处查看完整的讨论线程。
Image Credit: Wikimedia Commons
图片来源: Wikimedia Commons
翻译自: https://www.howtogeek.com/277896/why-does-linux-allow-users-to-remove-the-root-directory/
linux用户的根目录