As a user of the Terminal application and its command line interface, you will often find times when you need to run commands with root or superuser permissions. We normally do this using the sudo command when we just have one or two commands to run.
What if you have many commands and tasks you need to do with root permissions? You might not want to constantly type sudo before every command. The best method is to run your terminal session as the root user. You can switch to the root user with the following command.
sudo -s
My name is Eric, and as a software engineer, I use command-line interfaces such as Terminal daily. I often have tasks I need to do as the root user, and when I have multiple tasks, I find running Terminal as root is more convenient than using sudo commands for every task.
Above I have shown you the quick command to run your Terminal shell as the root user. If you want more details about this and another way to do this, keep reading, and I will discuss this further.
Switch to Root User
As mentioned above, switching to the root user can be very useful when you have many tasks or commands that need to be run with full permissions. Below are detailed steps on how to run the Terminal application as root.
Step 1: Open the Terminal application.
Use your preferred method to open the Terminal application.
Step 2: Type the command to switch to the root user.
Type the command as shown below and then hit the return key.
sudo -s
Step 3: Enter your password.
You will be prompted for your password, as shown in the image above. Here you will need to enter the password that you log in to your Mac with. The account you log in with needs to have administrator permissions.
Enter the password and hit the return key.
Step 4: Perform whatever tasks you need to perform.
You should now see a prompt that possibly shows you as the root user and has a # symbol at the end of the prompt.
If you don’t see the prompts similar to the ones shown above, you can verify that you are the root user by using the id command below.
id
Step 5: Exit
Once you finish performing the tasks you need to do as the root user, you should exit the root user session by typing the exit command.
exit
Logging In as the Root User
The steps above switch you to the root user, but they do not actually log you in as the root user, which is slightly different. When you only switch or become the root user, you have the root user’s id and permissions, but when you log in as the root user, you have all the root user settings.
The difference is slight and may not matter to most users, but it can make a difference depending on what you are doing. Logging in as the root user can be done with one command and is similar to the steps above. The command you will use to do this is shown below.
sudo su – root
You will need to enter your password just as you did in the previous procedure. Notice in the above login, the prompt is slightly different. It still has the # symbol, but it does not have the color scheme or show the current directory.
This is because it uses the root’s environment variables instead of my original environment variables. If we look at the current directory, you will also notice that we are now in the root’s home directory instead of the directory I was originally in.
FAQs
Below are some frequently asked questions about running Terminal as root.
Are there other ways to switch to the root user?
Yes, another method of switching to the root user involves using the same command you used to log in as the root user but leaving the – out of the command. To do this, you must specify that you are switching to the root user, as shown in the command below.
sudo su root
Notice there is no – in this command. As with the other commands, you will also need to enter your password here.
What does sudo stand for?
Sudo is a command that allows you to run other commands as a superuser (or root, in this case). Sudo is short for superuser do.
Can anyone become the root user in Terminal?
No, you must have administrator privileges on your Mac to switch to or log in as the root user. If you are the owner of the computer and did the initial setup of the Mac, then you will have admin permissions. If someone created your login account for you, you may or may not have them.
Why Do I need to exit after working as root? Why not just work as root all the time?
It may sound like a great idea, just always work as the root user, and then you can do anything. But remember that the root user has the power to delete and change almost anything on your system, so it makes it easier to accidentally remove files or change something you don’t want to change.
Conclusion
Running Terminal as root Mac can be useful for various reasons and is sometimes necessary when you have multiple tasks to do that need root permissions. Switching to root user or logging in as root user is easy as long as your user login has administrative permissions.
I hope the information I have provided above can help you to run Terminal as the root user. As usual, let me know if you have any questions or comments. I would love to get your feedback or help with any questions you may have.
Chetan
Thanks