Saturday, May 5, 2012

How to enable the root account login on OS X and other Unix and Linux systems

For security reasons, many Unix and Linux systems, including OS X and Ubuntu, install with a locked or disabled root account by default, with no password (not to be confused with a blank password). As such, it isn't possible to log directly into root shell or use su. Instead, the default user is given administrator access. That being said, below are three ways I found to access the root shell in the rare case it may need to be done.

Note: This presupposes the user already has administrator/superuser rights. Because of this, for most users the root account does not generally need to be enabled.

  • The following will open an sh or bash process with full root privileges: sudo sh sudo bash
  • The following will log you in with full root privileges: sudo su - If one runs su alone, it will prompt for the root password, but with sudo first it instead prompts for the current user's password. The dash at the end loads the root user environment.
  • The following sets a password for the root user, thereby enabling normal login for root: sudo passwd root On some systems, OS X not included, the following will reverse the last command, both disabling the root login and removing its password hash: sudo passwd -dl root
Some systems, including OS X, also have a special command, dsenableroot.
  • To enable root login: dsenableroot
  • To disable root login: dsenableroot -d


For more information:
  • Apple's official instructions for various versions of OS X using the GUI to enable root can be found here.
  • Ubuntu's site has a great article on various uses and misconceptions about sudo and root, as well as a few useful tricks, that can be found here.

0 comments:

Post a Comment