I did a similar mistake 30-odd years ago. I thought I was in a subdirectory and did a chmod only to realize that I was in the root directory. But in my case I did a wildcard chmod so it not only changed the permissions in / but in it's subdirectories. I quickly realized that the command execution was taking too long and stopped it but by then it was too late.
If you don't have a backup you are pretty much up the creek.
If you don't want to reinstall the OS (which is probably your most reasonable recourse) you might look at the permissions on the subdirectories to see if adding write privileges and fixing links to what's there them might help.
This is more or less what it should look like:
frankie@ubuntu-m8h:~/Downloads$ ls -l /
total 16777308
lrwxrwxrwx 1 root root 7 Oct 5 2022 bin -> usr/bin
drwxr-xr-x 5 root root 4096 Oct 15 19:09 boot
drwxrwxr-x 2 root root 4096 Jul 19 2018 cdrom
drwxr-xr-x 21 root root 5480 Oct 15 14:44 dev
drwxr-xr-x 161 root root 12288 Oct 17 06:50 etc
drwxr-xr-x 4 root root 4096 Nov 4 2020 home
lrwxrwxrwx 1 root root 34 Oct 21 2020 initrd.img -> boot/initrd.img-4.15.0-122-generic
lrwxrwxrwx 1 root root 34 Oct 21 2020 initrd.img.old -> boot/initrd.img-4.15.0-121-generic
lrwxrwxrwx 1 root root 7 Oct 5 2022 lib -> usr/lib
lrwxrwxrwx 1 root root 9 Oct 5 2022 lib64 -> usr/lib64
lrwxrwxrwx 1 root root 10 Oct 5 2022 libx32 -> usr/libx32
drwx------ 2 root root 16384 Jul 19 2018 lost+found
drwxr-xr-x 6 root root 4096 Nov 6 2022 media
drwxr-xr-x 2 root root 4096 Apr 26 2018 mnt
drwxr-xr-x 5 root root 4096 Oct 15 14:45 opt
dr-xr-xr-x 401 root root 0 Sep 5 08:09 proc
drwx------ 8 root root 4096 Mar 16 2023 root
drwxr-xr-x 42 root root 1220 Oct 19 16:56 run
lrwxrwxrwx 1 root root 8 Oct 5 2022 sbin -> usr/sbin
drwxr-xr-x 2 root root 4096 Sep 30 2022 scratch
drwxr-xr-x 38 root root 4096 Oct 15 14:44 snap
drwxr-xr-x 2 root root 4096 Apr 26 2018 srv
-rw------- 1 root root 17179869184 Mar 16 2023 swapfile_1
dr-xr-xr-x 13 root root 0 Sep 5 08:09 sys
drwxrwxrwt 24 root root 12288 Oct 19 16:55 tmp
drwxr-xr-x 14 root root 4096 Oct 5 2022 usr
drwxr-xr-x 14 root root 4096 Apr 26 2018 var
lrwxrwxrwx 1 root root 31 Oct 21 2020 vmlinuz -> boot/vmlinuz-4.15.0-122-generic
lrwxrwxrwx 1 root root 31 Oct 21 2020 vmlinuz.old -> boot/vmlinuz-4.15.0-121-generic
You have learned a great lesson that anyone seeking to be a *NIX admin needs to learn. And that is that unlike other operating systems, Ubuntu assumes you know what you are doing and will faithfully execute your commands as ill-advised as they may be. So welcome to the domain of the *NIX veterans.
Good luck!
I'll add the link to an answer that is way overkill for your situation for the benefit of anyone having this problem in the future. Please credit the user who put this in a comment with an upvote.
What if I accidentally run command "chmod -R" on system directories (/, /etc, ...)
-R
which had me create an equivalent install so I could create a script and reset the permissions back to what they should have been (mostly as a learning exercise; as it took time I ensured I wouldn't forget that mistake) with backups the usually fastest fix. – guiverc Oct 20 '23 at 00:10/bin/chmod
binary should still be usable ... Drop into a root shell from recovery mode and do/bin/chmod 755 /
then reboot and it should be solved. – Raffa Oct 20 '23 at 07:54sudo chmod 555 /
..." - That command is not dangerous, and does not result in the problems you describe. What command did you really run? Did you include-r
? – marcelm Oct 20 '23 at 09:53-R
option to make it recursive, most likely, it is just the root directory that has changed. So, that should be easy to fix. If you have a second computer (i.e., a notebook), you can boot it up with a bootable Ubuntu USB drive and then compare a working system with the system you made the mistake on. You just need something to compare with. Good luck! – Ray Oct 20 '23 at 10:08