0

I have a problem with my Ubuntu, I installed tomcat server and set it up, but I needed to change one directory and grant my current user read permissions over it so I executed:

chmod -R 644 /bin

And from there on I kept getting errors, like if i tried to change directory I would get output that there is no such command, so I tried to reopen it (terminal), now when I try to open terminal again it automatically closes, can anyone explain why is this happening and is there a way to reverse it ?

Zanna
  • 70,465

1 Answers1

4

Please don't change permissions in order to read root-owned files. In future, if you want to read a file you don't have access to, use sudo cat or sudo less or open a text editor with root permission. If you think you really need to change permissions for some reason, then first do research or ask a question about it. It's all too easy to break your system with chown and chmod.

Anyway, your user already had read permissions on that directory and all its contents. The /bin directory has permissions 755 or rwxr-xr-x, as do the vast majority of its contents. They can be read and executed by any user.

You removed the execution bits (644 = rw-r--r--), making the files readable for all, writeable for root, and executable for no user.

When you remove the execute bits from a directory, you make it impossible to enter the directory, except for root.

When you remove the execute bits from a file, you make it impossible to execute the file, even for root.

The Bash program is located at /bin/bash. You have made the directory it is in inaccessible, and you have made the binary file itself non-executable, so not even root can run it. chown and chmod are also in /bin, so you can't even use another shell to run them, if you happen to have one that isn't in /bin.

Reinstalling your system is the best way to be sure you've got everything right, but if you would like to try fixing it or you really want to avoid that, what you could do is boot from a live system (eg USB installation media or System Recovery), mount your root partition, and change the permissions from there. See terdon's answer here for the best method of doing this (replace /etc with /bin and use chmod instead of chown).

Zanna
  • 70,465
  • To further explain, execute bit on a directory is required to access anything beyond that directory in a path traversal, so for example /some/path/file1 can't be accessed without execute permission on /some and /some/path. You can list the contents of a directory with only read access to it, you just can't access any of those contents. – thomasrutter Dec 20 '17 at 01:21
  • I had to enable IDE to read content of those folders, IDE was installed under my user permissions and tomcat was owned by another user specially created for tomcat. I reinstalled and fixed everything. Also that /bin is not Linux /bin directory, but a directory in /opt/tomcat, I just didn't specify absolute path as I already had /opt/tomcat as working directory in my terminal so I had to grant certain read permissions to my user. – whatamidoingwithmylife Dec 20 '17 at 17:06