Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Terminal root user

Hi,


i activated the root-user in system preferences but the given password wont work in terminal, when i type a su (sudo) command.

Even my administrator or user password wont work...


Who can help?


Thanks

kitehi

MacBook Pro, OS X Mountain Lion

Posted on Dec 8, 2012 11:48 PM

Reply
17 replies

Dec 9, 2012 4:56 AM in response to kitehi

su wants the 'root' account password


sudo wants the password of the account you are currently using, and that account must either be a Mac OS X admin account or have had an entry added to the sudoers file.


When prompted for the password, you must enter it blindly followed by 'return'. The password will not be echoed, there will be no dots displayed, nothing will be displayed while you are entering your password. Just assume it is being entered, then enter 'return'.

Dec 9, 2012 6:12 PM in response to baltwo

> AFAIK, this lets you emulate the root user or am I missing something?


'root' is as state of mind. Or more accurately, if the User ID is 0, then you ARE root.


sudo su


Will give you a User ID of 0, so every thing you do until you exit the session, will be done as 'root'.


sudo su -


Will even give all the standard 'root' enviornment variables including the 'root's PATH. Essentially the current process' environment is trashed and 'root's shell initialization scripts are run before you are given control.


sudo su


Keeps your environment variables, but you are now running as 'root'.

Dec 10, 2012 8:44 AM in response to Frank Caggiano

sudo bash


is the same as


sudo su


in that it inherits your current environment variables.


sudo -i bash -l


is more analogous to


sudo su -


Giving you a clean environment, running a bash shell initialization to setup your root environment and leaving you in the /var/root home directory.


A lot depends on what you want to do when being root.


in most situations 'sudo command' is good enough.


If you want root prompt, then a lot depends on what you want to do. If running a few ls, mv, rm, etc... commands, sudo su or sudo bash is fine. If you are going to run some complex scripts, it may be important to have root login PATH and other environment variables that may not exist in your normal user account environment.

Dec 10, 2012 9:01 AM in response to Frank Caggiano

OK, I did not really mean to say they are the "Same", rather they are similar in that they both inherit your currnet environment vs the other 2 sudo examples where you get the 'root's environment based on running the root's shell initialization scripts.


Again it all depends on what you want to do as root.


I have had situations where inheriting my normal user environment caused problems.


But most of the time it does not matter, so I just use 'sudo command'.


NOTE: /bin/sh on Mac OS X is bash with a different name. So most of what you would do with bash can be done with /bin/sh. NOT 100% but enough that it doesn't matter that much. Again depending on what you want to do :-)

Dec 10, 2012 9:10 AM in response to BobHarris

Yes sh and bash on OS X are the same executable. I do beleive they will behave differently depending on argv0.


Of course if you use bash then there is almost no difference but if you use one of the others like csh or ksh then there is a difference and being able to run root in the shell you are comfortable wiht tends to limit stupid mistakes. 👿


But as you say there is almost no need to actually run as root, sudo will do 99.9% of the things you need to do.


regards

Dec 10, 2012 11:18 AM in response to kitehi

to give an example: sudo mdutil -a -i on

What password?

sudo wants the password for the account you are currently using.


That account MUST either be a Mac OS X 'admin' account, which you can check via System Preferences -> User & Groups. It should say 'Admin' under your account name. If it says 'Standard' or 'Sharing only', then these accounts would not work.


The alternative, would be to use a privileged account to add a new entry to the sudoers file, but if you do that, then effectively you will turn a 'Standard' user into an 'admin' user.


If you are NOT using an Admin account, and you have given 'root' a password, then you could do:


su root -c 'mdutil -a -i on'

password: root's_password

Terminal root user

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.