Results 1 to 3 of 3

Thread: Running Specific Commands As Another User

  1. #1
    Join Date
    Apr 2008
    Beans
    11

    Question Running Specific Commands As Another User

    I was trying to set it up so that I could have certain commands run as root without a password by certain users. I read that I should edit the sudoers file but what I'm doing doesn't seem to be working. I tried editing it with visudo to add
    Code:
    rhol ALL=(ALL) NOPASSWD:/usr/bin/update
    However, when I run the command
    Code:
    sudo -u root -H /usr/bin/update
    it lets me run every command and program as root without prompting for a password. I just want that one command to run. Can someone please explain what I'm doing wrong. Thanks in advance.

  2. #2
    Join Date
    Sep 2008
    Beans
    48

    Re: Running Specific Commands As Another User

    I don't know much about /etc/sudoers myself, so I can't really explain how it works, but adding this to the end of it should enable you to run a specific command (and only that command) without a password:

    Code:
    yourusername ALL=NOPASSWD: /path/to/command

  3. #3
    Join Date
    Apr 2008
    Beans
    11

    Re: Running Specific Commands As Another User

    I added your syntax to my sudoers file and it still didn't work. However, I decided I would check the owner of the script I had set as executable using
    Code:
    chmod u+x /path/to/script
    It turns out that somehow either when I created the file or when I ran the command the owner had changed to root and so it wouldn't let me run it without a password. I quick
    Code:
    chown rhol /path/to/script
    changed the owner back to me and now it works exactly like I want it to. Thanks for the help.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •