sudo access to specific folder - macos

On mac mavericks, i want to install few files without prompting user for sudo password. (Folder where i am trying to install require root access because it is present at / location). I can do this by modifying "sudoer" file and disable sudo password but this is unsafe and open up security risk. Is there any way i can provide sudo access only a particular folder? So when i try to write to this folder, sudo password prompt is not visible to user.
(All above task are done through command line)
Thanks for your help.

Related

How to disable sudo without using a sudo command?

I don't have access to my sudo password anymore, and whenever I try to download anything it always asks for the pass. Is there any way I can either see what my password is or just remove the sudo password altogther?

How do i get rid of the sudo requirement?

I am using MacOS Catelina and i often have to run my terminal stuff with sudo otherwise they fail. like when i use Visual Studio and IONIC to add stuff to global or when it tries to create dir etc.
Is there a way to change the logged in user to run elevated commands in terminal without sudo ?
You either continue using sudo or switch current user to root (it's not a recommended way)
The user account named ”root” is a superuser with read and write
privileges to more areas of the system, including files in other macOS
user accounts. The root user is disabled by default. If you can log in
to your Mac with an administrator account, you can enable the root
user, then log in as the root user to complete your task.
The root user account is not intended for routine use. Its privileges
allow changes to files that are required by your Mac. To undo such
changes, you might need to reinstall your system software. You should
disable the root user after completing your task.
It's safer to use the sudo command in Terminal instead of enabling the
root user. To learn about sudo, open the Terminal app and enter man
sudo.
Taken from https://support.apple.com/en-us/HT204012

Lost permission for sudo in OSX El Capitan

I'm new to using OSX (using El Capitan 10.11.3) and while trying to change permissions on a file using sudo, I accidentally corrupted it. Now whenever, I try to use sudo to install anything globally, I'm getting the following error message.
sudo: unable to stat /etc/sudoers: Permission denied
sudo: no valid sudoers sources found, quitting
Is there any way to solve it?
I'm also unable to even view the /etc folder
bash: cd: /etc: Permission denied
When I checked permissions on /etc folder, they are as follows
lrwxr-xr-x# 1 root wheel etc -> private/etc
I had the same issue and in my case the permissions of the root folder got corrupted. What people overlook is that / is in fact also a real, normal directory and just like every directory it has ownership and permissions. Ownership should be root:wheel and permission should be 755 (that's rwxr-xr-x).
The easiest way to restore both was starting Script Editor and then typing and running that script:
do shell script "/usr/sbin/chown root:wheel /" with administrator privileges
do shell script "/bin/chmod 755 /" with administrator privileges
You are prompted for amdin password and then chown and chmod come to the rescue. After that sudo was working again.
Disable System Integrity Protection (rootless)
Reboot the Mac and hold down Command + R keys simultaneously after you hear the startup chime, this will boot OS X into Recovery Mode
When the “OS X Utilities” screen appears, pull down the ‘Utilities’ menu at the top of the screen instead, and choose “Terminal”
Type the following command into the terminal then hit return:
csrutil disable; reboot
You’ll see a message saying that System Integrity Protection has been disabled and the Mac needs to restart for changes to take effect, and the Mac will then reboot itself automatically, just let it boot up as normal

Unable to save file without password prompt - Sublime Text 3

I'm having an issue all of sudden where I am being prompted on save for the password whilst in Sublime Text 3. I am working locally with Mamp Pro. The prompt message I get on save is:
Sublime Text.app wants to make changes. Type your password to allow this.
If I don't enter the password I get this:
Unable to save ~/Sites/mywebsite/templates/fl_sidebar/index.php
Error: administrator_copy_file(/tmp/.sublba2.tmp,
/Users/myusername/Sites/mywebsite/templates/fl_sidebar/index.php)
failed: AuthorizationExecuteWithPrivileges failed: ffff159a
I've never encountered this error before at all when using Sublime Text so I don't know how to fix it. I had a look at this (How to give Sublime Text 3 write permission to files in web server's DocumentRoot?) and tried the non-command line options, but it did not alter anything.
I stopped running MAMP, checked all permissions on the folder by Get Info, which stated I have read & write privilege. I restarted the Mac and opened up my local development again in sublime, made a change and was instantly asked for the password again.
I'm on OSX El Capitan Version 10.11.2
It appears you do not have write permission to that folder for your user. You can change the ownership of the folder with the following command: -
sudo chown -R INSERT_YOUR_USERNAME_HERE ~/Sites
This will recursively change the ownership of all the files in the ~/Sites folder to your user. Once you have ownership sublime should work correctly again.
In my case I didn't have ownership to the htdocs directory so I did sudo chown -R INSERT_USERNAME /Applications/XAMPP/htdocs

How can I access sudo command when bin permissions are not set for execute

Actually I'm new to mac.
I accidentally took away all permissions on bin directory for users. Now I cannot access any commands and moreover I cannot even access the root user on my mac, sudo command also not running. It says you don't have permission.
Can anybody please tell me how do I resolve this issue?
Thanks!

Resources