Why sudo does not work in a macOS terminal? - macos

I asked this question on mac rumors but as it's pretty developer specific no one could help so wondered if any developers here would know. Sometime in the last couple of weeks something happened that completely broke my sudo command. Now everytime I try to sudo anything it just comes up with a blank line. Nothing I can type into Terminal (or iTerm) does anything and I need to close the window.
I've got backups but don't know what files would have been broken and don't just want to reset my Mac to an arbitrary point in time and loose other work. I mostly just use sudo to edit /private/etc/hosts file and somehow now it's letting me edit and save that without sudo so I thought it might be stuck in sudo somehow but I've reset everything I can think of and haven't changed any settings that I know of.
I tried creating a new admin user and sudoing from that but it's the same.
I've tried following advice on various forums but none of them are working and I'm getting to the point I'm probably doing more damage to my mac. Anyone got any ideas of how to fix it or any files I can drag across from my backup that might fix it?
I've tried:
which sudo
and it comes up with /usr/bin/sudo which seems to be a valid file path.

After following this link - https://macperformanceguide.com/blog/2017/20170328_1326-macOS-10_12_4-sudo-broken.html - I found the solution and the problem. AMPPS had edited the sudoers file to include some NOPASSWD line which apparently doesn't work in 10.12.4. Commenting out those lines works
https://macperformanceguide.com/blog/2017/20170407_1157-macOS-10_12_4-sudo-broken-fix.html

Might be a good idea to compare your current /etc/sudoers with an old version just in case.
Also, keep in mind the expect file permission is:
chmod 0440 /etc/sudoers

I was also facing this issue for almost 3-4 months, It was bugging me a lot. It made me almost mad. Yesterday i decided to sit down and fix this issue once and for all.
After lot of reading and all, I found that AMPPS entry in sudoers file is culprit.
open sudoers file using sudo visudo command OR use some editor (take backup of sudoers file before making changes and also read guide to use "visodo" )
I commented 2 lines in my sudoers file and everything is fine now.
#%amit ALL= NOPASSWD: /Applications/AMPPS/Ampps.app
#%amit ALL= NOPASSWD: /Applications/AMPPS/ampps
Similar experience/solution has been shared by this blogger here,
You might not be having AMPPS on your machine so what worked for me, might not work for you.
Point to highlight is "There is something in there in your sudoers file which is causing issue, just find that line"

Related

Vim completely broken, can not use

Upon opening vim in my terminal, I receive this error
Error detected while processing CursorMoved Autocommands for "*"..function <SNR>
6_Highlight_Matching_Pair:
It repeats multiple times upon launch vim, then I can access vim however any movement (lkjh) causes the error to occur more.
I have deleted my .vimrc, updated my vim via brew. Neither has had any affect, vim is my go to IDE because I have it set up with plug ins in a efficient way that I prefer for programming.
Can someone please help me figure out what is occurring? Also, possibly important info I recently ran a brew update to update everything in my package manager.
Inside vim you can try using :scriptnames to get the list of loaded scripts and determine what files could be causing the issue. You can also check if vim can load without loading any additional scripts by launching with vim -u NONE.

-Bash Shell Script "No such file or directory"

Pretty new to coding and I am running into an error I've never seen before and would really appreciate any help navigating this :( Thank you!
I wanted to delete nvm, so I removed the folder following the advice given on StackOverflow. That FINALLY successfully deleted node from my mac (wanted to uninstall because I was running into dependency errors). The I used brew install to reinstall node. I can find the path to the node file (using which node). However when I run node -v I get the following bash (shell script??) error: -bash: /Users/Cindy/.nvm/versions/node/v12.14.1/bin/node: No such file or directory
I also followed #1219 and went into my bash_profile to delete the lines related to nvm. Now I don't know how to move forward with this.
I just want to be able to download node and run it properly to prepare for an interview in React and JS but I ran into these nasty bugs instead and morale is low. I'm lost now and I'm not sure if I just completely ruined my computer.

Mac OS terminal doesn't find commands

I have weird problem as all of the sudden terminal stopped reading any commands. Last weekend I installed Wordpress with PHP and mySQL and since that moment didn't have time to do anything more on laptop. Now I wanted to launch some react-native code but command wasn't found, then I tried different things to use some other commands and each time I get message
MBP-Mateusz-2:business-cards-native mateusz$ code .
-bash: code: command not found
and doesn't matter what command is that except standard ones like ls, cd etc. However when I try to write npm --version, or node --version, or launch visual studio code like before with code ., each time I get command not found. Doesn't anyone have issue like that? How to fix it as I'm super confused and have no idea even where to start.
You probably messed up your PATH environment variable, and now your computer cannot find the commands if you don't tell it directly where. The PATH variable contains the directories where the system should look for binaries if they're not in the current directory. If it gets corrupted for some reason, you won't be able to run any program from the terminal unless you pointed directly its location.
I would first run this command:
echo $PATH
so you can see which is the content of the PATH.
If it seems empty, or some critical folders are missing, try to add them temporarily:
export PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Then try to run the commands again from the same terminal and see if that worked.
If that works, check if you have a ~/Library/LaunchAgents/environment.plist file and its content. It is possible that there is a key for the PATH and that its values are pointing something of your Wordpress stack but not the system directories.
If that looks fine, look at the ~/.bash_profile file. Find any export PATH instruction that may explain your issues. If you can't find any, but still exporting the PATH worked out, add at the end of the file that instruction as a workaround for fixing the mess:
export PATH=$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
(notice that I'm ading $PATH in this last case so if there is any other path actually configured it is added as well)
Good luck.
EDIT: That's the usual issue people has, but now that I've read your comments, the issue seems a bit more serious. It looks like the mySQL setup destroyed your /usr/local/ folder, which means you lost all the binaries located there npm, code, etc.
If you have a backup of the whole filesystem (which by experience is unlikely), restore /usr/local folder.
If you don't have any backups, you can reconstruct /usr/local... by reinstalling the software that cannot be found. Reinstall npm, VSCode, etc, that will place their executables again in the /usr/local folders and from there you'll be good to go. Install brew (since it's likely that also got deleted) then try brew install node and see if now you can run npm. If that works out, I'm afraid you'll have to reinstall all the software you lost again.

Change file permission of com.apple.screensharing.plist file on mac

I'm trying to change the file permission of a file.
I have tried chmod 777 on the file and nothing seems to work.
I even tried manually navigating to it and unocking and changing the permissions via the answers here (chmod unable to change permissions), I am at a loss for how to change the file permission so I can edit this file to allow screen sharing on a different port...
For anyone else that has a mac I'm trying to follow the instructions here, https://superuser.com/questions/148095/how-to-change-the-default-screen-sharing-vnc-port-number-on-mac-os-x
sudo vim /System/Library/LaunchDaemons/com.apple.screensharing.plist
This is the path to the file, but I can't edit it no matter what I do. Even as super user!
I found the answer to this, there is a protection on the system file csrutil, you need to disable this by booting up into recovery mode and open the terminal program and run the command csrutil disable.
Make sure to reenable after making the change in recovery mode again!

Heroku CLI only works from root

I'm not sure why, but I can only run the Heroku CLI from root, not from a user.
When I run from user I get
>>heroku -v
and that's it. Nothing comes, nothing happens, it just freezes.
However when I open a new terminal window and change to root, it works fine
>>sudo su
Password:
>>heroku -v
heroku-cli/6.15.26 (darwin-x64) node-v9.6.1
>>
I have already tried uninstalling and reinstalling over and over again, I've used the Heroku direct download, as well as Homebrew, but I can't get it to work. I'm not really sure what I did to break my CLI, but how do I fix it? Where should I even look to see what the actual problem is?
UPDATES:
I've also changed shell types, and that did nothing to fix the issue either. The shell lists Terminal -- node /usr/local/bin/heroku -v at the top, if that helps.
As per the comments below, we tried copying the directory that the root user uses into my .local/share but this did not solve the problem either.
Further, I opened my activity monitor, and any time I try to run Heroku, it shows that node is taking up 95-100% of my CPU.
Spent nearly 12 days chatting with heroku staff. It turns out if your .netrc file is long (mine was 1.9 million lines), their parser has issues reading it.
Solution:
$ rm ~/.netrc
$ heroku login
Once the file is removed and you re-login it will create a new .netrc file without issues.
Why this happens:
My crontab uses an expect script to login to the blank environment. If you login over, and over and over, the .netrc file becomes huge.

Resources