Mac sudo as another user

Sudo Manual

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. 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. Learn more about Teams.

How to use the command line on Mac

OS X run bash command as another user with sudo privileges Ask Question. Here is the scenario: I am logged in as root and I want to execute sudo echo hello world as the user javier. Is there a way of running this without it prompting for a password? Javier Carmona Javier Carmona 1 1 gold badge 4 4 silver badges 15 15 bronze badges. You do understand that sudo runs a command as root? If you're already root, why do you need this? So, if you need any other environment variables, such as DISPLAY to open programs that use the window server, you have to omit the empty -.

“Sounds kinda cool! Tell me more please!”

Home Questions Tags Users Unanswered. How to login as a different user in terminal? Ask Question. I'm currently logged in as a normal user in OS X.


  • Environment?
  • free 3d games for mac;
  • how to sync playstation 3 controller to mac.
  • Presentations.
  • dupe for mac chestnut lip liner.
  • What are the differences between "su", "sudo -s", "sudo -i", "sudo su"? - Ask Ubuntu!

I'd like to start a terminal session and login as user foo. Is this possible? Have you tried using su - foo? Update based on the comments: The empty - tells su to make a full login. The login works fine but I tried mate myfile and I'm getting a "failed to connect to WindowServer" error. This isn't a critical fix, but it would be great to get this working. When you run sudo -s it will invoke a new shell, running as root.

sudo execute a command as another user --

The shell that is run is the default shell of your account. So when you have bash set as your shell the default on macOS you will get a bash shell running as root. Most other environment settings will remain the same:. Note: learn how to configure your shell prompt. Alternatively you can use sudo -i to invoke a root shell. In most cases sudo -s should serve well. However, when you want to avoid any customization you might have set in your user environment and work in more pristine environment then it is good to know sudo -i exists.

The main difference between these tools is how they verify if you are authorized to switch. When you run su without a username, it assumes root.


  1. filtrado mac router movistar zte.
  2. open jpg files on mac.
  3. mac os x terminal color coding?
  4. Using the sudo command in Terminal requires an administrator password.
  5. But since logging in as root is disabled by default on macOS, it will fail. It asks for your credentials to verify you.

    Return Values

    You do not need the credentials of the other user, whether it is root or a different user. Since the root account login is usually disabled on macOS, you cannot use su root - or su - to get a root shell. Use sudo -s or sudo -i instead. We will look at strategies for privilege escalation and the opposite in scripts in the next post. Informative and instructional post, as usual. For those of us who contrary to the suggestion given in Part 1 run as a standard user, the process for using sudo is slightly more complicated.