Search code examples
macosbashterminalrootsudo

OS X run bash command as another user with sudo privileges


I have root access in my terminal and I am trying to run a command as another user with sudo privileges and I can't make it work.

Here is the scenario:

I am logged in as root and I want to execute sudo echo hello world as the user javier.

I currently have sudo -u javier sudo echo hello world but it prompts for a password.

Is there a way of running this without it prompting for a password?


Solution

  • If you're a sudoer, then you could edit the /etc/sudoers file for the user javier using vim :

    sudo vi /etc/sudoers
    

    and add something like :

    javier ALL=(ALL) NOPASSWD:ALL
    

    Save the file and then execute your command. You should be good to go.