13

I accidentally ran a chmod 754 ./ when I was at the root directory on the server which runs Ubuntu 18.04.

Now I cannot use commands like sudo or pkexec, nor can I change anything. What should I do? Does it affect other user?

  • 3
    Was it chmod 754 ./ or chmod -r 754 ./? The latter would be much more destructive while the former should be easy to recover from. – Nonny Moose Jun 27 at 22:10
  • 1
    @NonnyMoose Thank you so much, and I really appreciate that. It was without r, which is not recursive. – Bo Ni Jun 28 at 0:41
16

Note: this answer assumes that you neither passed the --recursive nor the -R argument to chmod, i.e. the ONLY file/directory that you modified was /.

If you found this question and answer through a search engine and used the recursive (-R or --recursive) method, please go here!

I ran the exact command you posted in your question on a VM, and recovered it with (almost) no trouble at all.

Since you only modified one directory/file, the solution is simple: just change it back!

You actually don't need a Live CD to fix this. Ubuntu has a built-in recovery mode. These steps assume your computer started turned off.

  1. Boot to GRUB. If it already displays when you boot, just boot into GRUB like you usually would. Otherwise, follow the instructions in this answer. In either case, make sure to cancel automatic boot by moving the initial selection with the up or down arrow keys. Note: GRUB crashed the first time I tried this. Be persistent.
  2. Choose Advanced Options for Ubuntu, then the first entry that ends in (recovery mode).
  3. Once recovery mode boots, select the root shell option with the arrow keys and hit enter.
  4. Press enter again to enter maintenance mode.
  5. Type chmod 755 /Enter
  6. Type rebootEnter

That's it! Unless there were any other complications, your system is recovered.

  • @Dɑvïd Oh, you're right. I didn't realize that holding shift only worked in BIOS mode. I'll edit that in. – Nonny Moose Jul 12 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.