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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值