osx - Get around permission errors

07
2014-07
  • Starkers

    In Ubuntu, whever I run into a permissions error I just run the command as sudo at it usually works. Not the case in OSX:

    $ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
     From https://github.com/Homebrew/homebrew
     * [new branch]      master     -> origin/master
    error: unable to unlink old 'Library/Aliases/0mq' (Permission denied)
    

    as sudo:

    $ sudo ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
    -e:69: warning: Insecure world writable dir /usr/local in PATH, mode 040777
    Don't run this as root!
    

    Not sure what I should be doing. I run into this sort of thing all the time and while I could sudo chown the relevant directories I will be doing that all the time.

    I can't sudo brew install either as brew 'cowardly refuses' to operate as a super user. I'm just confused because I feel like I'm attempting to do something stupid, and yet the Ubuntu equivalent of this, sudo apt-get install is considered the correct way to install new applications?

    I could also create a new user who is actually a super user and install things as him, but Ubuntu doesn't let you do this as it's a bad idea and I agree having a user with limited abilities and sudoing only when needed seems like a much better idea.

  • Answers
  • Lqueryvg

    /usr/local/ should not be world writable; that's a bad thing - and the error/warning message is quite right to point it out. (I wonder how it got that way in the first place ?)

    Also, you don't always have to resort to chown'ing directories - you should consider user/group ownerships and permissions as pieces of the same puzzle.

    In this case, I suggest you remove the world write bit from /usr/local and try again.

    sudo chmod o-w /usr/local
    

    EDIT:

    I found this in the script you are trying to run.

    This script requires the user #{ENV['USER']} to be an Administrator. If this
    sucks for you then you can install Homebrew in your home directory or however
    you please; please refer to our homepage. If you still want to use this script
    set your user to be an Administrator in System Preferences or `su' to a
    non-root user with Administrator privileges.
    

    Therefore I'd suggest you add yourself temporarily as an administrator. I think this probably just adds you to the admin group. If so, you could also make /usr/local (and any other subdirs thereof) group owned/writable by anyone in the admin group.

    sudo chgrp admin /usr/local
    sudo chmod g+w /usr/local
    

    This would be much more acceptable from a security point of view than blanket changes. I've seen some "solutions" where people chown the entire /usr/local contents to their own id.

    Tut tut tut.

    Or the other way (as the above suggests) it to install as non-root into a home directory somewhere.


  • Related Question

    ubuntu - Using pscp and getting permission denied
  • Espen

    I'm using pscp to transfer files to a virtual ubuntu server using this command:

    pscp test.php user@server:/var/www/test.php
    

    and I get the error permission denied. If I try to transfer to the folder /home/user/ I have no problems.

    I guess this has to do with that the user I'm using doesn't have access to the folder /var/www/. When I use SSH I have to use sudo to get access to the /var/www/ path - and I do.

    Is it possible to specify that pscp should "sudo" transfers to the server so I can get access to the /var/www/ path and actually be able to transfer files to this folder?


  • Related Answers
  • ngen

    You're most likely correct that you don't have access to /var/www/. What you can do is chmod /var/www/ to allow guest to write and change it back to original state once complete (I would advice against this). You can add the user to the group that owns /var/www/ and make sure the group is set for read/write/execute.