Sudo chown mistake? - command-line

I have been trying to install Homebrew on my Mac but ran into permission problems since my user is not an administrator.
I followed the suggestions here: https://stackoverflow.com/a/16450503/4909923
su -l admin
sudo chown -R "$USER":admin /usr/local
sudo chown -R $USER:admin /Library/Caches/Homebrew
Now I'm concerned that I have wrongfully changed the ownership of these folders to a specific user. Will it impact my normal user negatively?
changing ownership of /usr/local to a specific user is not a solution. It is a terrible hack and a workaround if you have a single user system. But then you might as well just chown -R / $USER:$USER – fijiaaron Jan 23
If this was a stupid thing to do, how do I restore it to normal?
It should probably look like the image with /lib/ which is another folder in /usr/, with system Read & Write and wheel Read Only.
It should probably look like this (another folder in /usr/):

I think the permissions I mentioned in the comment should be fine, but if you want to be sure everything is set at its default, you can uninstall Homebrew using this script and then reinstall it from scratch.
You can also follow this advice for resetting the permissions.

Related

VS Code: NoPermissions (FileSystemError): Error: EACCES: permission denied

I'm trying to save a file called app.js on a folder called js.
Vs Code pop up this:
Failed to save 'app.js': Unable to write file 'vscode-remote://wsl+ubuntu-18.04/js/app.js'
(NoPermissions (FileSystemError): Error: EACCES: permission denied, mkdir '/js')
I tried:
sudo chown -R user /mnt/c/Users/myUser/Documents/myFolder/proyectFolder
but I still can't save this file.
Try this, fixed it for me
sudo chown -R username path
Example:
sudo chown -R emanuel /home/emanuel/test/
In the SSH terminal:
Recommended :
sudo chmod -R 777 folder_name_where_your_file_exists
or
sudo chmod -R 755 folder_name_where_your_file_exists
this works for me
sudo chown -R $USER:$USER /home/
TLDR;
If you're using a docker container, avoid making files from within the container because the owner and group permissions may cause problems with your editor (in my case VS Code)
I was running docker container for a Django project from Windows Terminal and using VS Code to edit my code.
It is a Linux file (since everything in Linux is a file) permission problem that arises because the files don't have proper user and/or group permissions. So VS Code tries to tell us that.
The problem I found only happened when I created files from within my docker container.
I would run docker exec ... bash
make new files using touch /path/to/file from the container bash
then try to edit those files on VS Code (say urls.py) only to get the scary permissions error preventing the file from saving.
I suspect that making files from within the container embellishes those files with different owner and group settings than your system would default to if you just ran the commands locally (not in the container).
Changing the file permissions with chown -hR and chgrp -hR would do the trick but to avoid the error altogether I stopped making files from within the container.
Try activating polling:
This worked for me during I tried using wsl.
The below is for individual file:
sudo chown yourUserNAme filename
For an entire directory it will be (when you write ls to terminal, you should see your directory to execute this command):
sudo chown yourUserNAme dirName
For recursive (i.e files and folders inside a folder):
sudo chown -R yourUserNAme dirName
Note: yourUserNAme is, if you do pwd under any Documents, you will see the path: /home/jhon/Documents. Here user is jhon.
Run VS Code as administrator and it will fix the problem.
https://answers.microsoft.com/en-us/windows/forum/all/error-in-vs-code-destination-directory-and-says/e70dc626-6b12-4791-a960-8b704e57098d
Install the extension Save as Root in Remote SSH in VS code.
While saving press Ctrl + Shift + P.
This open the command palette.
Search Save as Root
It is a Linux user permissions problem.
you should use the command:
sudo chown -R $USER:$USER.

How to remove sudo privileges from a user in CentOS 7?

I have root and one other user on my CentOS machine. With other user i can use sudo to perform most of the administrative tasks. Now, I want to take this privilege from this user, So that it can not use sudo anymore.
Does anyone have an idea how to implement that?
One way to achieve that on Centos is by performing the following 2 steps:
Firstly, you have to remove any mention of the aforementioned user
(the one for which you do not want any sudo privileges) from the
/etc/sudoers file or (if it exists) from any file under the
/etc/sudoers.d path.
Secondly, you must remove the user from the wheel group in /etc/group.
(Optional) Finally reboot.
e.g.:
For user centos sudo vim /etc/sudoers or sudo vim /etc/sudoers.d/90-cloud-init-users and remove or comment something
like centos ALL=(ALL) NOPASSWD:ALL (save and quit afterwards).
Then sudo vim /etc/group and change the line wheel:x:10:centos to
wheel:x:10: (save and quit afterwards).
(Optional) Finally sudo reboot.
Hope that helps!

Permissions When Attempting to install mongodb

I am trying to install mongoDB and need to tap their repo with homebrew. However, every time I run the command, I get a permission error. I am on macOs if that helps
I tried running it with and without sudo and get errors either way.
brew tap mongodb/brew
It should just tap the repo
Without Sudo-
touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied
touch: /usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart/.git/FETCH_HEAD: Permission denied
With Sudo-
Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.
I figured out the issue. I had the change the permissions of the
/usr/local/Homebrew
directory so that it could be edited by anyone. I did this using the GUI, but you could do it using this command
cd /usr/local && sudo chown -R 777 Homebrew
If you're in Catalina, then give the owner user permission to "Homebrew" folder:
sudo chown -R $(whoami) /usr/local/Homebrew/

MongoDB config error

Pretext: this has been asked before and i've tried implementing several solutions from previous posters. The only thing i can seem to get working is running mongo as sudo.
I'm not exactly sure what i'm doing wrong. I'm trying to do a tutorial using mongodb and every time i try to run the software i get back an error that its in a read-only directory. I'm on a mac running OS Sierra, i can force run it with sudo but i know thats wrong. I've been searching for an answer for awhile and i have already adjusted the folder permissions to 775 and nothing, then 777, still nothing.
Any help pointing me in the right direction would be greatly appreciated!
to resolve the "warning soft rlimits to low" check out this link - https://gist.github.com/tamitutor/6a1e41eec0ce021a9718
Lets start over as you are bouncing around on what you are trying.
Open activity monitor and kill any mongod process.
Go to your terminal and type which mongo - lets say it shows you download directory
cd to that directory and you should be in the bin directory
cd /mongo download directory/bin
sudo bash
mkdir -p /data/db
chmod 777 /data
chmod 777 /data/db
ls -ld /data/db this will validate you see the data/db directory as 777
exit
You're back in your mongo bin directory - if you are in /usr/local/bin skip this part.
If you are not in /usr/local/bin you will need to copy the mongo files to /usr/local/bin
sudo bash
ls - make sure you are in the correct directory
cp * /usr/local/bin
exit
which mongo should now show /usr/local/bin
type mongod to start it
open a new terminal and type mongo to connect to the instance
I recommend downloading Robo 3T (formally RoboMongo) to quickly check that you can connect.
If you do those steps, you should have no issues connecting to your local Mongo instance.
Your mongod.conf files should be in /usr/local/etc - check there to confirm you have your local host set.
Should be like net:
bindIp:127.0.0.1

Subversion svn update - Not working

I'm trying to setup subversion, so everytime someone commits a change, it updates a working directory that we'll use on a dev box as the 'test' site.
I've setup post-commit, and added the line:
#!/usr/bin/perl /usr/bin/svn update /home/administrator/sites/checkmyid --username root --password xxx
Can anyone tell me why this doesn't work when run automatically, but when I run it at the command prompt:
sudo ./post-commit
/home/administrator/sites/svn
It works fine?
I've tried chaning the owner of the working directory to www-data but it doesn't seem to want to work?
FIXED IT MYSELF
Basically, it was a permissions problem. I used the command
sudo chown -R www-data /home/administrator/sites/checkmyid
And now it works perfectly!
Your post-commit script contains bash code, but the shebang is saying to use Perl to run it.
Plus, shebang lines should be on their own line; put the actual commands to run on another line.
sudo chown -R www-data /home/administrator/sites/checkmyid