10

I recently started doing Unix and Mac development, coming from a hardcore work environment in .NET. I am learning terminal use and how to mkdir and ls and vim, but it's all under my actual name.

I just bought a MacBook Pro Retina. My Unix account shows my name. But I need to login as root.

I tried this command in terminal to switch to root:

su - root

but it won't take my password, and I really don't know which password to provide?

migrated from stackoverflow.com May 7 '13 at 0:24

This question came from our site for professional and enthusiast programmers.

  • try sudo su - root You probably just want to run things with sudo instead of actually switching to root. – Shawn Balestracci May 6 '13 at 21:28
  • root isn't enabled on mac by default why do you need to be root? – FDinoff May 6 '13 at 21:28
  • If you are running linux on that macbook pro (which works perfectly fine) you should be able to use that command. However it requires the root password, not yours, since you have to prove that you are indeed permitted to act as that root user. – arkascha May 6 '13 at 21:30
  • 2
    I've worked on mac and Linux for many years and I have very rarely needed to log in as root. Tell us what you're trying to do, and we'll tell you a better way (most likely use sudo instead). – Kevin May 6 '13 at 21:36
17

You should actually use sudo -i to start an interactive shell. Then, type your login password. It won't appear; that's okay. Keep typing, then press Return.

To exit the interactive shell, type exit or ^D (that's Control-D, not Command-D). You'll then be back in your normal terminal.


Regarding your original question: Use sudo su.

The su command grants you access to another user's account, but you need to know that user's password. Since root is disabled by default (and for good reason), and has no password, you can use sudo, which grants you elevated privileges for one command, to overrule that rule. When sudo prompts you for your password:

[sudo] password for huang:

just enter your password. It won't appear due to security reasons (so people can't see how long it is) but it is being entered. Press Return when done.

  • -1 for the unexplained passive aggression. I have no idea what alternative approach you're saying sudo -i is "actually" better than, or why, and nor do I know what change to the "original" question you're insinuating occurred (presumably inside of the grace period, and thus not appearing in the edit history?). Without those details, this answer is pretty incomprehensible. It sounds like you're saying sudo su is superior to sudo -i in some circumstances outlined in a no-longer-accessible revision, which is an obviously unhelpful way to frame the answer for future readers. – Mark Amery Jun 20 '18 at 10:55
1

Just type the following command:

sudo su

enter image description here

0

This only works if you're an admin user, which you shouldn't be I think. Better create another user with admin rights. Whenever you need admin rights for installing software, you have to enter the login for an admin user.

Let's say you give this new admin user the name "huangadmin". It may be something else (like admin), but I don't think it's a good idea to give it the name "root".

Then, in the terminal, you need to use su huangadmin. The password for this account is requested, and then you're user huangadmin. Then you can use sudo su and become root.

0

very simple command to run as sudo :

sudo -s what_ever_command_you_want

enter image description here

0

OS Sierra

dsenableroot

More info: How to Enable the Root User on Your Mac

0

By default root user is disabled on Mac, you need to first enable root user on Mac. Refer: https://www.dataneb.com/single-post/2018/08/29/How-to-enable-root-user-on-Mac

From top left hand side, choose Apple menu () > System Preferences, then click Users & Groups (or Accounts).

Click the lock icon , then enter an administrator name and password.

After you unlock the lock. Click Login Options, right next to home icon.

Now Click Join (or Edit), right next to Network Account Server. Now Click Open Directory Utility.

Click lock icon in the Directory Utility window, then enter an administrator name and password.

From the menu bar in Directory Utility: Choose Edit > Enable Root User, then enter the password that you want to use for the root user. You can enable/disable/change password for root user from here.

Now go to Terminal and switch user to root and test.

Once root user password is set in Directory utilities. Type su root in your terminal and enter the password. Note local admin user password is not same as root user.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.