Mac mojave - sudo uid reset - terminal

long story short,
1.my PATH got messed up so the zsh throws an "command not found" error in the terminal
tried to uninstall and reinstall the homebrew to see if that does anything - it did not.
now sudo throws me an error
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin
the reason why(well my guess) sudo throws this error that is that while
I manually delete the files as the homebrew recommended, I must have deleted or done something in
/usr/local so now sudo uid is not 0 anymore.
I have tried
mount -uw /
chown 0 /private/etc/sudoers
exit
and these instructions
A. https://apple.stackexchange.com/questions/157772/sudo-etc-sudoers-is-owned-by-uid-501-should-be-0?fbclid=IwAR0HPT64TzzkuKs1ymsqb2l8HThXqRpGifX_QAdzrK5z5XgecavTzWiQVh0
B. https://forums.macrumors.com/threads/not-able-to-use-sudo-commands-in-terminal.2101126/?fbclid=IwAR3BL-Sajkrsp02i5MCAKM7DZ0C83xUFOg9pzRhpG1hLrzpk9FbnDbbjoaM
but none of them worked.
What is the last thing I can do?
If I delete the drive and re-install it(disk utility), will it also change the sudo problem?
That is, of course, the last thing I would like to do. but I am considering it now.
Any thoughts?
HELP!

After digging everywhere, I found the answer here,
My sudo command not working
One of the main issues I had was that the sudo uid set to 501 instead of 0.
#GordonDavisson had a solution using "Script Editor" and run the code
do shell script "chown root:wheel /etc/sudoers; chmod 440 /etc/sudoers; chmod -N /etc/sudoers" with administrator privileges
as he mentioned.
This successfully changed my root. I checked it by running
ls -l /etc/sudoers
in the terminal.
After this, I could re-install the homebrew.
Though I encounter unusual steps, where homebrew was running,
it asked me several times to enter the password for different stages
which did not happen before.
But after re-installing the Homebrew, I changed my $PATH
export PATH=$PATH:/usr/local/git/bin:/usr/local/bin
and now I can live again!

Related

VS Code Will Not Save Changes - Mac

I know this question has been asked before, but none of the advised solutions have worked for me. I am on a Mac and trying to save changes to a VS Code file. When I press save, it says
Insufficient permissions. Select 'Retry as Sudo' to retry as superuser.
When I choose to "Retry as Sudo" I enter my password and it says
Failed to save... Error using --file-write: EPERM: operation not permitted
I have tried a couple of different things to open VS Code with admin privileges, including running it from the terminal with the command:
sudo open /Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron
and manually adding VS Code to my path using the commands
cat << EOF >> ~/.bash_profile
# Add Visual Studio Code (code)
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF
I have yet to find anything that affects the failed to save error, and if anyone has any suggestions, they would be greatly appreciated!
05-03-2021
This works for me.
Sudo chown –R username folder-path
e.g
sudo chown -R sampath /Users/sampath/Desktop/Test/renoTracker/platforms/ios
Its no longer an issue after running:
$ sudo chown -R username .
Hope this will resolve all kind of permission issues.
I have fixed my issue by adding user here in permission. May be this can solve your issue

How disable need to sudo? Setting root to admi, sudivo, and disabling SIP didn't work

I am having to type "sudo" before most terminal commands, and am also getting EACCES errors sometimes even when using sudo when chained to a secondary file/folder.
I've done the standard setting of root user to admin, added my username with all permissions in visudo, and successfully disabled SIP. It may have to do with permissions I may have changed when I first got my Mac years ago.
Does anybody have any ideas as to what could be wrong?
Sometimes you use sudo command1, you also encountered permission denied. It's because the command1 will invoke another process which don't have root prividge. In this situation you can put command in a script, and use sudo bash script, or su to change to root user. And sometimes sudo filename also permission denied, it's that you not have the x priviledge, you can sudo chmod 744 filename, then execute the command.
methods to avoid type sudo passward every minutes.
method 1 recomended. sudo -i
method2 use sudo visudo or sudo vim /etc/sudoers and put this in it. this will make username user neednot to pass passward when use sudo.
username ALL=(ALL) NOPASSWD: ALL
you can refer here for config for one command
hope helps.
Log in and open your terminal app. Run these two commands:
sudo echo >> /etc/sudoers
sudo echo "$(id -u -n) ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
Now you can run sudo without a password. Do normal stuff under your regular account and when you want to run as root for a while do:
sudo bash
macOS includes a "root user" that can be enabled using Directory Utility. Have a look at the following article from Apple: Enabling and using the "root" user in OS X. The article, while not explicitly saying it, implies that using the root user is the same thing as sudo.
The Apple article includes some warnings about use of the root user, but if you think about it, it's no more risky than deliberately disabling the password required by sudo. Either way you're creating an unrestricted path to root-level functions, so do be careful about it!
None of these solutions worked as things are. Ended up wiping my computer's hard drive and permissions settings went back to normal.

Meteor will not run without Sudo?

On OSX Yosemite and the latest version of meteor (1.0.1), no matter how many times I uninstall and reinstall it, I can't seem to get it running without sudo. My user account is an administrator account. But meteor refuses to run without sudo. The errors I'm getting are all:
-bash: meteor: command not found
I've seen a few posts on here with similar problems. I've tried repairing disk permissions with disk utility. I've tried:
sudo chown -R $myUsername /usr/local/bin/meteor
I'm not sure what else I can do, because it seems to be a permissions issue. Does anyone have any suggestions?
Additional info that might help:
$ sudo which meteor
/usr/local/bin/meteor
$ sudo ls -l /usr/local/bin/meteor
-rwxrwxrwx 1 root wheel 3528 Dec 18 23:14 /usr/local/bin/meteor
$ ls -ld /usr/local/bin
drwx------ 6 502 wheel 204 Dec 18 23:14 /usr/local/bin
By the way, ls -l /usr/local/bin/meteor only works with sudo.
After we clarified the permissions of the meteor executable and its base directory,
the problem became quite clear:
The Meteor binary is located in /usr/local/bin/meteor
Your user didn't have permission to the directory /usr/local/bin
The steps to resolve:
Add permission on the base directory: sudo chmod +rx /usr/local/bin
If necessary, add the base directory to PATH: PATH=$PATH:/usr/local/bin
For future reference:
When you get this kind of error: -bash: XYZ: command not found
The first thing to check is find the absolute path of XYZ, for example /path/to/XYZ
Try to run with the absolute path /path/to/XYZ
If running with /path/to/XYZ gives -bash: /path/to/XYZ: Permission denied that means you have a problem with permissions on the file and/or directories:
You need read and exec permission on the file itself: sudo chmod +rx /path/to/XYZ
You need exec permission on all path elements leading up to the file: sudo chmod +x /path /path/to
After fixing permission issues, running with /path/to/XYZ should work
After fixing permission issues, if running with XYZ (without full path) still doesn't work, that means /path/to is not on your PATH. Fix with PATH=$PATH:/path/to
Note: the above sudo chmod commands give permissions (read and exec) to all users: owner + group + other. In the case of the OP (and in most common cases), this is perfectly fine.
In situations with more sophisticated permission setup, you might need to be more specific, and use g+rx instead of +rx.
(for the record)
If it works with sudo, and without sudo you get command not found, that means that meteor is on the PATH for root but not for your user. To make it work for your user, you need to find the path to meteor and add it to your user's PATH. For example:
Become root with sudo su -
Find the path of meteor, run command: which meteor
Logout from root (Control-D) to return to your user
Add the base directory to PATH, for example if earlier which meteor gave you /usr/local/bin/meteor, then do this: PATH=$PATH:/usr/local/bin
After this, it should work with your user. To make it "permanent", add the last step in your ~/.bashrc.
If this still doesn't work, then perhaps your user doesn't have the execute permission on the file. Fix that with this command:
sudo chmod +x /usr/local/bin/meteor
From your comments it also seems your user doesn't have permission on the /usr/local/bin directory itself. Fix that with this command:
sudo chmod +rx /usr/local/bin
Shouldn't need an admin account to run it, standard user account works fine. You can locate the meteor file by typing which meteor. It will tell you what file is being used to execute.
Try removing the .meteor folder in your home directory, something like rm -rf ~/.meteor and the script from the bin folder rm /usr/local/bin/meteor or rm 'which meteor' (speech marks there are the ones above ~)
And then reinstall meteor without sudo using the curl https://install.meteor.com/ | sh command.
Should hopefully install with all the correct permissions...

What does "You should probably `chown` them" mean?

I've just installed Homebrew. When I run brew doctor I get this
Warning: Some directories in /usr/local/share/man aren't writable.
This can happen if you "sudo make install" software that isn't managed
by Homebrew. If a brew tries to add locale information to one of these
directories, then the install will fail during the link step.
You should probably `chown` them:
/usr/local/share/man/de
What does "You should probably `chown' them" mean? Can someone explain what exactly Homebrew wants me to do?
Ok, so chown is the unix command to change the ownership of a file.
Homebrew is asking me to change the ownership of /usr/local/share/man/de so that Homebrew can write to it. Homebrew runs with the same permissions as I do, so making myself the file's owner should solve the problem.
Running the following fixes the problem:
sudo chown $(whoami) /usr/local/share/man/de
Check the owner and the permission rights:
ls -la /usr/local/share/man/ | grep de; ls -la /usr/local/share/man/de/ | grep man1
Change it:
/usr/bin/sudo /usr/bin/chgrp admin /usr/local/share/man/de /usr/local/share/man/de/man1
/usr/bin/sudo /bin/chmod g+rwx /usr/local/share/man/de /usr/local/share/man/de/man1
Now you can use brew without any problems ;-)
Your system is ready to brew.
In fact, a simple command should do all the work.
sudo chown $(whoami) /usr/local/share/man/*/man1
chown is used to change who has the ownership of a file. In this case the reference to sudo implies that files installed as the superuser will not be accesible by homebrew when run by a regular user rendering these options useless, and most likely causing an error or undesired result if such a file is attempted to be accessed

Spotlight won't turn on: Console says: mds[pid] (Fatal) Server: mds must be run as root. exiting

I turned off spotlight and was very thorough about it. So thorough that I can't get it turned back on. I need to install a program from the Mac App Store (& App Store relies on mds), so if anyone has information on how to install an App Store program without mds at all (spotlight), that would be even better.
So my problem is that spotlight is complaining it can only run as root, but I can't for the life of me figure out why it isn't. From what I understand, launch daemons in /System/Library/LaunchDaemons are automatically launched as root as long as they have the correct permissions. Every file that directory is rw-r-r. Here are the commands I've been using to unload/load spotlight from launchd:
sudo mdutil -a -E -i off
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist
sudo rm -rf "/.Spotlight-V100"
sudo chmod 600 /System/Library/CoreServices/Search.bundle/Contents/MacOS/Search
I also rename the mds executables in /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Support, adding a .bak extension.
To reload it, I essentially undo those steps. However it's not working right now. I've searched for the error on google, but no dice. I reloaded the mds binaries from the Snow Leopard install image, didn't do anything. I've repaired permissions 4-5 times and manually looked up the tree to see if I noticed any permissions were wrong, but everything is root:wheel 755 like I assume it should be in the Frameworks folder, and rw-r-r in the LaunchDaemons folder. However mds is constantly spitting messages to the console that say
mds[pid] (Fatal) Server: mds must be run as root. exiting.
Anyone have any clue what is going on? I'd rather not reformat right now since I've put quite a long time into setting up this computer and I just want to install one program from the App Store.
Thanks!
Well, wouldn't you know as soon as I break down and post on SO I find the solution: I found someone's spotlight-enable script and pasted it into my terminal. Rebooted, spotlight working, installed program, disabled spotlight again. This is what I used:
sudo chmod 775 /Library/Spotlight;
sudo chmod 755 /System/Library/Spotlight;
sudo chmod 755 /System/Library/PreferencePanes/Spotlight.prefPane;
sudo chmod 755 /System/Library/Services/Spotlight.service;
sudo chmod 755 /System/Library/CoreServices/Spotlight.app/Contents/MacOS/Spotlight;
sudo chmod 555 /usr/bin/mdimport;
sudo chmod 555 /usr/bin/mdcheckschema;
sudo chmod 555 /usr/bin/mdfind;
sudo chmod 555 /usr/bin/mdls;
sudo chmod 555 /usr/bin/mdutil;
sudo chmod 555 /usr/bin/md;
As Thilo pointed out, this isn't really programming related so it can be moved to Super User or whatever else anyone things is better.

Resources