Issue
I am setting up my first server using apache2 on Ubuntu 14.04 and installed phpMyAdmin,
I tried to run the phpMyAdmin file in /etc/phpmyadmin/ but did not have permission
I used sudo chmod 777 -R /etc/
to give myself permission to run the file. When I went to restart apatche2
I get the error
sudo: /etc/sudoers is world writable
sudo: no valid sudoers sources found, quitting
sudo: unable to initialise policy plug-in
I tried pkexec chmod 0440 /etc/sudoers
but that gave me the error
sudo: unable to stat /etc/sudoers: No such file or directory
sudo: no valid sudoers sources found, quitting
sudo: unable to initialise policy plug-in
and now I cant even access the etc folder I get the message:
You do not have the permissions necessary to view the contents of “etc”.
When I open the terminal I get: bash: /etc/bash.bashrc: Permission denied
Google has turned up nothing that fixes the problem and I don't want to mess around with the permissions in case I make the situation much worse.
Thanks in advance.
Solution
I don't want to sound rude, but speaking as someone with 20+ years experience running unix servers, you probably need to learn more about systems before being this cavalier with sudo. As you have seen here, it is easy to cause yourself huge headaches (or worse, completely trash a system) by using sudo or other root access methods.
Two pieces of advice before I continue with my answer:
Whenever using sudo, stop and try to think through what the result is going to be. If you aren't relatively confident you know what it is, maybe you should not run the command.
chmod 777
(or666
) is almost never the right thing to do. Whenever that's the solution you're about to try, it's a red flag to re-think the problem and try something else first. It is almost always the wrong answer, and quite often has damaging side effects or security implications.
That said, you're already in this situation. At this point, you are no longer able to use sudo because it is failing its own security checks. Unfortunately, sudo would have been the easiest way to fix this.
There are only a couple of things you can do now that I can think of.
First, if you can log in as root somehow, just do that, fix the permissions on the sudoers file, and sudo will work again.
If you are not able to log in as the root user, another possibility is to try to mount your filesystem on another unix system, then manually fix the permissions, unmount the filesystem, and boot back up your original environment. How to go about that depends on your system, whether it is a VM or a physical system... that's a much bigger topic to go into, so I won't try to.
Of course, you always have the third option of just wiping the system and reinstalling it and starting over. If your system is new and doesn't have substantial work done on it yet, maybe that's a reasonable option. That's a question for you to answer, though...
NOTE: By whatever method, if you manage to fix the permissions so that sudo works again, that is just the beginning of the repairs. You made everything under the /etc directory readable and writeable by any user or process. I wouldn't be surprised if you find other software or services complain about this, and cleaning it up will be kind of a mess. I can't tell you everything you need to do to fix it, but the first thing I would do is:
# fix the /etc/shadow file where authentication lives
sudo chmod 0640 /etc/shadow
Good luck... you may also want to seek help at https://askubuntu.com/
Answered By - Dan Lowe Answer Checked By - Gilberto Lyons (WPSolving Admin)