Linux 更改根文件夹和子文件夹的所有者 (Ubuntu 13.04)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17451577/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 23:22:56  来源:igfitidea点击:

Change owner of the root folder and subfolders (Ubuntu 13.04)

linuxunixubuntusudochown

提问by Mikhail Panteleev

I accidentally set owner of root folder (/) and all subfolders to one user by command

我不小心通过命令将根文件夹(/)和所有子文件夹的所有者设置为一个用户

$ sudo chown -R 'userName' /*

Now I wanna set owner back to root user by command

现在我想通过命令将所有者设置回 root 用户

$ chown -R root:root /*

But I have no permission for this operation. If i use command

但是我没有权限进行这个操作。如果我使用命令

$ sudo chown -R root:root /*

it returns

它返回

 sudo: effective uid is not 0, is sudo installed setuid root?

What should I do to fix that?

我该怎么做才能解决这个问题?

回答by hek2mgl

:O I offer my condolence!

:OI 表示哀悼!

The problem is that the sudo binary itself must be owned by root. If you have the root password you could just get root to fix the problem:

问题是 sudo 二进制文件本身必须由 root 拥有。如果你有 root 密码,你可以得到 root 来解决问题:

su

If not, you could boot using a rescue system, mount the partition and

如果没有,您可以使用救援系统启动,挂载分区并

chown root:root /mnt/usr/bin/sudo

or fix the whole problem using the rescue system.

或使用救援系统解决整个问题。

But it will be hard to fix all that ownerships. I would suggest to craft a script that reads the file ownerships from a vanilla installation of your system (having installed the same packages as you) and applies them to the crashed system. (Custom files in the /home/... you'll have to chownyourself) Without such a script it will get really hard but it should be easy to code that

但是很难修复所有这些所有权。我建议制作一个脚本,从系统的 vanilla 安装中读取文件所有权(安装了与您相同的软件包)并将它们应用于崩溃的系统。( /home/ 中的自定义文件...你必须chown自己)没有这样的脚本会变得非常困难,但应该很容易编写代码

回答by Alfe

You broke your system pretty badly. Next time be more careful using sudo.

你破坏了你的系统。下次使用时要多加小心sudo

  • Now, start your system using a rescue disk, probably your install disk.
  • Mount your broken file system in the rescue system.
  • Fix the permission/owner stuff.
  • Reboot using your original system.
  • 现在,使用救援盘启动您的系统,可能是您的安装盘。
  • 在救援系统中挂载损坏的文件系统。
  • 修复权限/所有者的东西。
  • 使用原始系统重新启动。

Depending on how much you changed using that chown, you will have to fix a lotin step 3. You probably might want to have a look at a working proper installation of the same system to find out which user should be the owner of things like /dev/memetc.

根据你使用多么太大的改变chown,你必须解决很多在第3步你可能可能想看看在同一系统的工作正确安装,以找出哪些用户应该是的东西,如业主/dev/mem等.

A re-install of the OS might be faster.

重新安装操作系统可能会更快。

回答by jaypal singh

I am guessing when you ran the first command you also ended up modifying the ownership of the /usr/bin/sudoexecutable.

我猜当您运行第一个命令时,您也最终修改了/usr/bin/sudo可执行文件的所有权。

It is saying that effective UID isn't 0(since root has EUID equal to 0).

据说有效 UID 不是 0 (因为 root 的 EUID 等于 0)

So try to change owner of /usr/bin/sudo, and then try change the ownership of other files.

所以尝试更改 的所有者/usr/bin/sudo,然后尝试更改其他文件的所有权。