8 Replies Latest reply: Feb 6, 2013 10:05 AM by Linc Davis
chfa Level 1 Level 1 (0 points)

Is there a good way that one can run a login script as root these days?  In doing some research, I learned about login hooks, which assist with that.  Though with further research, I learned that newer OSes don't support that (or, rather, are depricated).  Is there maybe some sort of app you can run which will give you root access at a standard user login?  I am needing to work with the current user's home directories- as in, rename stuff that a standard user can't seem to do.

 

Though on a related note, I noticed that OS X creates extended attributes in the user's folders which says that "everyone" can't delete them.  Renaming them wouldn't count as the delete attribute since I'd use the mv command on it, would it?  I haven't tried yet but I'm assuming that isn't my answer, anyway.

 

Thanks!


OS X Mountain Lion (10.8)
  • 1. Re: run login script as root
    Topher Kessler Level 6 Level 6 (9,340 points)

    You can try looking up the man pages for launchd and launchd.plist, and see how you can have a launch agent invoke a script or other process at startup or login for the system or a specific user, and have it run scripts as another user.

  • 2. Re: run login script as root
    Frank Caggiano Level 7 Level 7 (23,815 points)

    sudo is the standard way to run a command in the terminal as the super user

     

    # sudo ls

     

    will run the ls command as super user. You have to run this from an Admin account and you will be asked for your password. The first time you run it you will get a bunch of lines telling you to be careful.

     

    Your post seems to be asking a bunch of different things and its hard to see just what it is you are trying to do.

     

    regards

  • 3. Re: run login script as root
    Linc Davis Level 10 Level 10 (117,870 points)
  • 4. Re: run login script as root
    chfa Level 1 Level 1 (0 points)

    @Frank, here is what I'm trying to do.

     

    At a standard user login (not someone who's an administrator), I want to change that user's Documents folder to be an alias to a different directory.

  • 5. Re: run login script as root
    chfa Level 1 Level 1 (0 points)

    @Topher,

     

    I see that the man page says, "

    If you wish your service to run as a certain user, in that user's environment, making it a launchd agent is the ONLY supported means of accomplishing this on Mac OS X. In

         other words, it is not sufficient to perform a setuid(2) to become a user in the truest sense on Mac OS X."

     

    but it also says, "

    In Darwin, the canonical way to launch a daemon is through launchd as opposed to more traditional mechanisms or mechanisms provided in earlier versions of Mac OS X. These

         alternate methods should be considered deprecated and not suitable for new projects."

  • 6. Re: run login script as root
    Frank Caggiano Level 7 Level 7 (23,815 points)

    is this somthing that needs to be done each time you or the other user logs in or does it just need to be done once?

     

    If it is ongoing then yes you might have to do this with some sort of login script. But if it is a one time thing (make the alias once and that's it), then you can use the sudo command.

     

    Roughly you would log in as yourself, open the terminal app and then  use the sudo command to change the other users folder.

     

    If it is a one time thing post back and explain EXACTLY what it is you need to do and we'll try to come up with the steps to do it.

     

    If it is an ongoing thing then I'm not sure what the best path is to take.

     

    regards

  • 7. Re: run login script as root
    Topher Kessler Level 6 Level 6 (9,340 points)

    Do you want this to be done whenever a new user is created, and have it be done to a specific directory, or do you want it to update dynamically to point to any specified directory whenever the user logs in?

  • 8. Re: run login script as root
    Linc Davis Level 10 Level 10 (117,870 points)

    I want to change that user's Documents folder to be an alias to a different directory.

     

    You don't need root to do that; you just need to clear the ACL on the folder, which can be done with the user's privileges. It's probably something you shouldn't do at all, but that's not your question.