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 - rootbut it won't take my password, and I really don't know which password to provide?
47 Answers
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.
1OS Sierra
dsenablerootMore info: How to Enable the Root User on Your Mac
1Just type the following command:
sudo su 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.
very simple command to run as sudo :
sudo -s what_ever_command_you_want By default root user is disabled on Mac, you need to first enable root user on Mac. Refer:
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.
if you want to su from your standard account, you need to add it to /etc/sudoers. This works regardless of the root account being enabled or not after you created root's password.
It will allow you to sudo su, sudo -i, or sudo any command (better); su - root or su never works from a standard account.
Needless to say, try this only if you really know what you're doing as a super user.