ivcfadmin
By:
ivcfadmin

I accidentally typed root@xxxxx:/var/www/html/xxxxx.com/listimages# sudo chown -R www-data:www-data /. How do I restore the file permission?

September 25, 2016 4.2k views
Linux Commands Ubuntu

I accidentally typed root@xxxxx:/var/www/html/xxxxx.com/listimages# sudo chown -R www-data:www-data /. How do I restore the file permission?

I got this error whenever I try to use sudo

sudo: error in /etc/sudo.conf, line 0 while loading plugin `sudoers_policy'
sudo: /usr/lib/sudo/sudoers.so must be owned by uid 0

sudo: fatal error, unable to load plugins

withou it I cant change owneship.

5 Answers

You will have to restore from backups.

what happens if you do not use sudo?

This is pretty hard to solve.
Maybe there is very little chance but usually problems like these finishes with Rebuilding droplets or restoring backups.

I will try to give you few ideas how to fix but I can't guarantee it will work, or it will make it work worse. Use it on your own risk.

First problem is that you don't know anymore who is default owner of files. You can try to give owner of everything to root. Maybe it will work better, but root is not default owner of all files/folders.
You can spin one $5 droplet and look at default owners.

If you are using Ubuntu 14.04.x you should have option of Recovery kernel.
On Ubuntu 16.04, you are out-of-luck with Recovery kernel, as it is not possible to change kernel anymore. Maybe you can contact support and ask them to enable it for you, but I'm not sure is it possible anymore.
If you have this possibility or DO let you somehow use it, you will need Interactive Shell, in which you can try giving everything to root or looking at default owners and giving it to files respectively.
You can give everything to root with (not recommended, really):

  • chown -R root:root /.

want to give to their default owner syntax of chown command is:

chown user:group file

or if you want to apply to all files in directory

chown -R user:group directory

Note the -R switch, it means recursively, it will apply permissions/owner to all directories/files in selected directory.

If you don't have recovery kernel, I have found somewhere this command:

  • pkexec chown root:root /usr/bin/sudo

It should return your sudo so you can use chown from your system.
You can try it as root user if it is not working from non-root user. If you disabled root logins via SSH, you can use Console. Go to Control Panel, select your droplet and click console. If you don't have password, you can use option Reset root password from Control Panel.
After that try sudo to see if it works.

Anyways with this wall of text, I really, really recommend you to rebuild droplet or restore backup. You will never know right permissions, and server can break anytime.
Good luck

by Justin Ellingwood
Linux includes a filesystem checking utility called fsck that can be used to recover your system in cases of corruption. In this guide, we will discuss how to attempt to recover your filesystem if there are filesystem issues by using the fsck kernel and a recovery ISO.

usually if you use this command:

sudo chown root:root -R /

it WILL not fix the problem because of different services are running (eg. MySQL, Apache2, PHP) have all different ownership of files with a different username

the best way is to backup /var/www oe wherever the web root folder is and start over by Zipping it into a zip (google this) or a tar backup the database and using [https://transfer.sh](http://) to upload it using curl and downloading to another Droplet using wget

the mysql database is stored at

 /var/lib/mysql 

i think

then then copy the database over to new server and. use this command:

sudo chown mysql:mysql -R /var/lib/mysql

use if phpmyadmin is destroyed

that one your using is completely destoryed

usually if you use this command:

sudo chown root:root -R /

it WILL not fix the problem because of different services are running (eg. MySQL, Apache2, PHP) have all different ownership of files with a different username

the best way is to backup /var/www oe wherever the web root folder is and start over by Zipping it into a zip (google this) or a tar backup the database and using [https://transfer.sh](http://) to upload it using curl and downloading to another Droplet using wget

the mysql database is stored at

 /var/lib/mysql 

i think

then then copy the database over to new server and. use this command:

sudo chown mysql:mysql -R /var/lib/mysql

use if phpmyadmin is destroyed

that one your using is completely destoryed

Have another answer? Share your knowledge.