Ubuntu /etc/sudo.conf is owned by uid 1000, should be 0 的一种解决方法
Ubuntu 命令行操作过程中,不小心将 /etc 整个文件夹的所属者都给了当前用户(非root),导致了使用sudo 会出现以下问题,想将/etc所属改回来也不行了,进退两难
sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: error initializing audit plugin sudoers_audit
test@test-ubuntu:~$ sudo chown -R test /etc
[sudo] password for test:
test@test-ubuntu:~$ sudo cd /etc
sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: error initializing audit plugin sudoers_audit
test@test-ubuntu:~$ ll /etc
total 1240
drwxr-xr-x 140 test root 12288 11月 5 13:57 ./
drwxr-xr-x 21 root root 4096 4月 8 2022 ../
drwxr-xr-x 3 test root 4096 4月 19 2022 acpi/
-rw-r--r-- 1 test root 3028 4月 19 2022 adduser.conf
drwxr-xr-x 3 test root 4096 4月 19 2022 alsa/
drwxr-xr-x 2 test root 4096 11月 5 11:02 alternatives/
也即sudo 不能使用了,修改/etc/sudo.conf也修改不了
test@test-ubuntu:~$ ll /etc/sudo.conf
-rw-r--r-- 1 test root 4573 2月 14 2022 /etc/sudo.conf
test@test-ubuntu:~$ sudo chown root /etc/sudo.conf
sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /etc/sudo.conf is owned by uid 1000, should be 0
sudo: /etc/sudoers is owned by uid 1000, should be 0
sudo: no valid sudoers sources found, quitting
sudo: error initializing audit plugin sudoers_audit
test@test-ubuntu:~$ chown root /etc/sudo.conf
chown: changing ownership of '/etc/sudo.conf': Operation not permitted
test@test-ubuntu:~$
解决方法
根据网上提的方法,
Ask Ubuntu
1、执行下面命令
pkexec chown root:root /etc/sudoers /etc/sudoers.d -R
sudo 能够输入密码了。后三句话错误没有了。
2、再执行 命令将/etc 所属修改回root
sudo chown -R root /etc
sudo:*** 只出现一次,再修改就没有出现了。/etc 又恢复以前的用户(组)了
/etc文件夹的属性不要轻易改动。
参考链接 Ask Ubuntu