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.

  • 6
    chmod/chown is like vodka. At first it seems to solve all your problems, but later you just get a bigger headache. Don't use them (especially with -R!) unless you are 100% confident you know what you are doing. Were you able to access recovery mode successfully? Your question leaves that a bit unclear. – Seth Dec 21 '16 at 22:48
  • 5
    your installation is screwed. like they say "chown fixes your problem, but one day it gives you a headache." you will have to reinstall Ubuntu. –  Dec 21 '16 at 22:49
  • I have a repository that I need to push, how can I force to connect to the Internet, push the code and the restart the system? – lmiguelvargasf Dec 21 '16 at 22:55
  • use a livecd ^^^ –  Dec 21 '16 at 23:00
  • If you didn't have enough permissions to update PyCharm but you were able to run sudo, why didn't you update PyCharm as root in the first place? – jamesdlin Dec 22 '16 at 08:03
  • 1
    This situation can be fixed pretty easily. Please consider repairs before contemplating reinstallation – Zanna Dec 22 '16 at 08:29

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
  • 70,465
  • 2
    Most importantly, dbus-daemon-launch-helper needs its setuid bit reapplied as well (chmod u+s after chowning). You can find those using find -perm /7000. – user1686 Dec 22 '16 at 07:55
  • I think you forgot the /mnt on the utempter path (2nd to last code block, last line) – chrki Dec 22 '16 at 10:06
  • 2
    @fkraiem we did some polling in chat and we all found that everything belongs to root with these or very similar files with different group ownership (a mod suggested I post an answer). I believe this repair strategy would well work for most users, and would likely be preferable to reinstalling. I haven't suggested anything destructive here. – Zanna Dec 22 '16 at 13:32
  • 1
    @fkraiem it's still a valid answer. It's not only for OP. If it works for OP, that's great; they got what they needed. If it doesn't, it still might work for someone else who visits this page. Besides, at this point, with the only other option being a reinstall, what's the harm in trying? – TheWanderer Dec 22 '16 at 13:41
  • @fkraiem you're wrong. it can still work for other people, so why harm the answer if it's valid? –  Dec 22 '16 at 20:47
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,122
  • 21
  • 114
  • 172
  • 1
    Good point. Not everything is necessarily owned by root. Recovery at this point is likely impossible. – Seth Dec 21 '16 at 22:51
  • what about backups?!? –  Dec 21 '16 at 22:52
  • @KazWolfe, I have a repository, and I need to push the code I have there. Is there any way to force a connection before reinstalling the OS? – lmiguelvargasf Dec 21 '16 at 22:52
  • @Edity good point, editing in now. – Kaz Wolfe Dec 21 '16 at 22:53
  • 1
    backups are really important peoples, one day your pc might have not enough blood and backups are like from a blood doner –  Dec 21 '16 at 22:54
  • all im saying is, backups are important. your pc's life might depend on one –  Dec 21 '16 at 22:54
  • @lmiguelvargasf From your OS as is? No. You can, however, use a live environment, pulling your SSH keys and any important files from your /home on your bad install. – Kaz Wolfe Dec 21 '16 at 22:57
  • 1
    @imiguelvargasf like seth said, recovery at this point is likely impossible. unless you have enthernet. wait try that –  Dec 21 '16 at 22:57
  • @Edity, thank you. I tried ethernet. I was able to connect to the Internet, and push my code. But I will need to reinstall the OS. – lmiguelvargasf Dec 21 '16 at 23:10
  • 2
    @lmiguelvargasf no need to reinstall... – Zanna Dec 21 '16 at 23:36