4

I wanted to update PyCharm, and when running Pycharm it was not possible since it said that I did not have enough permissions. So I run the following command:

$ sudo chown -R $USER$USER /usr/lib/

I was able to update PyCharm successfully, but now my Internet connection is not working, and actually I was not able to run sudo after I access the recovery mode following this tutorial.

I really need my Internet connection working again, so please I would appreciate your help to solve this issue.

I have to mention that I am using a dual boot.

2 Answers2

14

Actually, no need to reinstall. This situation is quite reparable. I just ran the same command on my system and fixed it in about 10 minutes.

You will need to either boot in recovery mode, or use a live USB/DVD of any Linux version (preferably Ubuntu!)

If you prefer recovery, please see How do I boot into recovery mode?

I used a live USB with Xubuntu 16.04 that I had to hand. If using a live session, after booting, open a terminal and identify your root (main) partition, using commands such as lsblk and sudo fdisk -l. When you know which one it is (it will likely be an ext4 partition), mount it. Here I am calling the root partition /dev/sda1 - you need to replace this with the real label.

sudo mount /dev/sda1 /mnt

now check it is the right partition by doing ls /mnt - you should see usr sys proc dev home root and other things you would expect to find at the top of the filesystem tree. OK, let's fix the ownership (in all these commands, please take careful note of the : and be sure to put these in the right places).

sudo chown -R root: /mnt/usr/lib

That almost fixes it. On my system, before I broke it, I checked out all the ownerships on that location

$ find /usr/lib -not -user root

returns nothing - root owns everything, but

$ find /usr/lib -not -group root -ls

Turned up this:

-rwxr-sr-x   1 root     mail          /usr/lib/emacs/24.5/x86_64-linux-gnu/movemail
-rwxr-sr-x   1 root     tty           /usr/lib/mc/cons.saver
-rwsr-xr--   1 root     messagebus    /usr/lib/dbus-1.0/dbus-daemon-launch-helper
-rwxr-sr-x   1 root     utmp          /usr/lib/x86_64-linux-gnu/utempter/utempter

Your system will not be exactly the same, but you should chown those files if you have them, and look for equivalents if not (for example if you system is 32-bit, you would have x86 instead of x86_64). I fixed these with:

sudo chown :mail /mnt/usr/lib/emacs/24.5/x86_64-linux-gnu/movemail
sudo chown :tty /mnt/usr/lib/mc/cons.saver
sudo chown :messagebus /mnt/usr/lib/dbus-1.0/dbus-daemon-launch-helper
sudo chown :utmp /mnt/usr/lib/x86_64-linux-gnu/utempter/utempter

(if using recovery mode, you will not need /mnt at the start of those paths)

As pointed out by @grawity, you also need to repair the setuid bit on dbus-daemon-launch-helper which is cleared by chown:

sudo chmod u+s /mnt/usr/lib/dbus-1.0/dbus-daemon-launch-helper
Zanna
  • 72,312
8

Any sort of chown operation on system directories is very dangerous.

The easiest way to solve this problem would to be just to reinstall your operating system entirely.

If you're lucky (and a bit of a risk-taker), you might be able to recover by simply running the below command from recovery mode:

chown -R root:root /usr/lib

While most files are owned by root in /usr/lib, there might still be the occasional file that isn't which will cause major problems if it's not actively owned by the appropriate user. In fact, on your (average) Linux installation, most files in this directory are owned by root/root, so this is definitely worth a shot if reinstallation is undesirable.

Otherwise, you'd have to go through each file and manually re-assign permissions to their normal values (typically meaning owned by root, but not in all cases). On occasion, you can just re-install all packages (using apt --reinstall install <packagename>), but this is not guaranteed, and may still cause more headaches than it solves. Really, you'd be going through each file and running dpkg -L on them.

As for preserving your files in your current system (if you go down the reinstall your OS path), you can use a flash drive in recovery mode. If you need to upload some files to Git at the last second, you can probably use a Live DVD (pulling SSH keys and anything important from your wrecked install).


In the future, to prevent this exact type of problem from happening again, make sure you have a (working -- check it!) backup of your system and any important files.

Also, it's important to note that sudo is not a one-shot-fix-all solution for any permission error, and should not be used that way! If there's a permission error, there's probably a very good reason you don't have permissions to do that thing, so investigate and solve it in a sane manner.

Kaz Wolfe
  • 34,680