8

By mistake I have made permission changes for /etc. Now it's giving me the following error message:

bash: /etc/bash.bashrc: Permission denied  
I have no name!@chandan-Inspiron-5520:~$ sudo /etc/init.d/apache2 restart  
sudo: unable to stat /etc/sudoers: Permission denied  
sudo: no valid sudoers sources found, quitting  
sudo: unable to initialize policy plugin  
guntbert
  • 13,134
Satish Prasad
  • 81
  • 1
  • 1
  • 3
  • related: http://askubuntu.com/questions/115358/changed-etc-permission-in-oneiric-ubuntu11-10-by-using-sudo-chmod-665-etc?rq=1 – Kevin Bowen Jun 16 '13 at 23:23

2 Answers2

11

What I would do :

$ sudo su
chown -R root:root /etc
find /etc -type f -exec chmod 644 {} +
find /etc -type d -exec chmod 755 {} +
chmod 755 /etc/init.d/* /etc/rc.local /etc/network/* /etc/cron.*/*
chmod 400 /etc/ssh/ssh*key

Maybe it's not sufficient, but without any backup, that's a good start.

podarok
  • 149
6

As a next step after sputnik recommendation, you could do this: On a fresh install of a ubuntu server with the same version as your broken one, run this:

find /etc -type f -executable | awk '{printf("chmod a+x %s\n",$0);}' > setexec.sh

Then import the script setexec.sh (using wget or ftp) and execute it on the broken server. on ubuntu 13.04 this step restored most of the functionalities.

Eric Carvalho
  • 54,385
  • here is a list from my desktop: http://askubuntu.com/questions/508359/restore-default-system-file-folder-permessions/508366#508366 – Rinzwind Aug 08 '14 at 00:50
  • 1
    Thank you for this idea. I used a variant of it to copy all permissions, not just the execute bit: find /etc/ -exec stat -c "chmod %a %n" '{}' \; > setperms.sh – Dave James Miller Oct 28 '16 at 13:51