I made another admin account in my MacOS Monterey for my programming job. Then I had to change ownership of Homebrew directories to make it work.
sudo chown -R $(whoami) /usr/local/Homebrew/ /usr/local/var/homebrew /Library/Homebrew/ /usr/local/Cellar
When I came back to my main account, Homebrew doesn't work. so I decide to to delete the new account and change the ownership of directories back to my main account.
the problem starts when I ran the following command and I need to revert it back.
sudo chown -R $(whoami) /usr
after that sudo command doesn't work and shows following exception:
➜ ~ sudo vi x.t
sudo: /usr/local/bin/sudo must be owned by uid 0 and have the setuid bit set
here is the sudo permissions:
➜ ~ ls -l /usr/bin/sudo
-r-s--x--x 1 root wheel 1246544 8 Dec 10:39 /usr/bin/sudo
I activated the root account to change permissions but it doesn't work. I also reinstalled the OS but there is no success. I tried to replace /usr directory with my friend /usr directory with the same OS but the directory and it's file are read only. I could not change things in Recovery Mode Terminal.