权限 - 如何将/etc文件夹所有者更改回root:root?

分享于 

3分钟阅读

ubuntu

 

问题:

昨天,我意外地更改了/etc文件夹组的所有者:


sudo chown -R pts:apache /etc



稍后,当我尝试将它更改回root:root时,它显示这个错误:


sudo: /etc/sudo.conf is owned by uid 1001, should be 0


sudo: /etc/sudo.conf is owned by uid 1001, should be 0


sudo: /etc/sudoers is owned by uid 1001, should be 0


sudo: no valid sudoers sources found, quitting


sudo: unable to initialize policy plugin




答案1:

尝试此命令


pkexec chown root:root /etc/sudoers /etc/sudoers.d -R




答案2:

并非/etc中的所有文件都是root:root


-rw-r----- 1 root daemon 144 Oct 21 2013 at.deny


drwxr-sr-x 2 smmta smmsp 4096 Apr 1 2016 mail 


-rw-r----- 1 root shadow 1110 Aug 10 2018 gshadow 


drwxr-s--- 2 root dip 4096 Apr 28 2019 chatscripts


-rw-r----- 1 root shadow 1462 Aug 5 2019 shadow




答案3

这三种方法在这种情况下有效:

从liveCD (Ubuntu安装介质,尝试Ubuntu而不安装选项)引导,在liveCD中挂载root分区,并用它更改/etc文件夹的所有者:


$ sudo mount -t ext4 -o rw /dev/sda1 /mnt


$ sudo chown -R root:root /mnt/etc



重新启动

或者,如果你知道root的密码:


$ su 


# chown -R root:root /mnt/etc




$ pkexec chown root:root /etc/sudoers /etc/sudoers.d -R


$ sudo chown -R root:root /etc


$ ls -ailh / | grep etc


1046529 drwxr-xr-x 139 root root 12K кві 22 12:38 etc



对于不属于root的文件和目录,可以运行:


sudo chown root:daemon /etc/at.deny


sudo chown -R root:bind /etc/bind


sudo chown -R root:dip /etc/chatscripts


sudo chown -R root:lp /etc/cups


sudo chown root:shadow /etc/*shadow*


sudo chown -R root:landscape /etc/landscape


sudo chown mpd:audio /etc/mpd.conf


sudo chown -R postgres:postgres /etc/postgresql


sudo chown -R root:dip /etc/ppp


sudo chown -R smmta:smmsp /etc/mail



/etc/中的文件和目录列表不属于root,你可以从其他工作ubuntu机器上获得几乎相同的配置。



FOLD  roo  ROOT  permission  Owner  
相关文章