Generally you want to keep ownership of your personal files separate from the root user. This is why you create a account for yourself as an administrator. The accepted way, under OS X, to gain root level access is to use the sudo
command from the Terminal application. For example, if you want to see the partitioning of your internal drive the command is
gpt -r show /dev/disk0
which if entered will result in the following error message.
gpt show: unable to open device '/dev/disk0': Permission denied
To use the command, you need to use sudo
as shown below.
sudo gpt -r show /dev/disk0
If you want to become the root user to avoid entering sudo
, you can just enter sudo sh
. The exit
command can be used to exit from being the root user.
If you want to execute an application as the root user, you can by using the Terminal application. For example, if you want to launch the Finder as the root user, enter the following command.
sudo /System/Library/CoreServices/Finder.app/Contents/MacOS/Finder &
To avoid the confusion of having two Finder applications open at the same time, it is usually best to quit your Finder application first. This can be done using the following terminal command.
osascript -e 'tell application "Finder" to quit'
One word of caution: preceding a command with sudo
is not the same as becoming the root user. For example, the commands
sudo echo $USER sudo echo $SUDO_USER
result in the same output as the commands shown below.
echo $USER echo $SUDO_USER
If you become the root user (the superuser), then the same commands result in a different output. This can be verified by entering the commands shown below.
sudo sh echo $USER echo $SUDO_USER sudo echo $USER sudo echo $SUDO_USER exit