What a root shell is and when you need one
A root shell is a command line where you have administrator permissions — the ability to change system files, install software, and run commands that affect the whole machine instead of just your user account. Most of the time you work as a regular user, which protects the system from accidental damage. When you need to do something that requires those higher permissions, you open a root shell instead.
You will need root access to install system packages, change network settings, modify files in protected directories, or manage user accounts. If a command fails with "permission denied," that usually means you need to run it as root. The most common way to do this is with the sudo command, which lets you run a single command with root permissions without switching to a full root shell.
Key Takeaways
- The sudo command runs a single command with root permissions and is safer than opening a full root shell.
- To open an interactive root shell, type sudo -i or sudo su at your regular command prompt.
- Your system will ask for your user password (not a root password) before allowing sudo commands, unless you have already typed it recently.
- When you are in a root shell, the prompt changes to a hash symbol (#) instead of a dollar sign ($), which reminds you that you have full system permissions.
- Type exit to leave the root shell and return to your regular user account.
Using sudo to run a single command as root
The safest way to do something that needs root access is to run just that one command with sudo, then return to your regular user permissions. Type sudo followed by the command you want to run. For example, to install a package with apt (on Ubuntu or Debian), you would type sudo apt install package-name. The system will ask for your user password, and if you have typed it recently, it may not ask again for a few minutes.
This approach is safer than opening a full root shell because you stay in your regular user account between commands. If you make a typing mistake, it only affects that one command instead of everything you type afterward. Most Linux tasks can be done this way, one command at a time.
Opening an interactive root shell with sudo -i
If you need to run many commands in a row that all require root access, opening a full root shell is faster than typing sudo before each one. Type sudo -i at your regular command prompt. The system will ask for your password, and then you will see a new prompt that ends with a hash symbol (#) instead of a dollar sign ($). That hash symbol tells you that you now have root permissions.
When you are in a root shell, every command you type runs with full system permissions. This means you can change any file, install anything, and modify system settings without typing sudo each time. Be careful what you type in this state, because there is no safety net — the system will not stop you from deleting important files or breaking your installation.
The difference between sudo -i and sudo su
Both sudo -i and sudo su open a root shell, but they load your environment slightly differently. sudo -i loads the root user's environment, which means you start in the root home directory and use root's settings. sudo su keeps your own user environment but gives you root permissions, so you stay in your own home directory and keep your own settings.
For most tasks, the difference does not matter. sudo -i is more commonly used and is the recommended approach. If a command behaves differently depending on where you are or what settings are loaded, try the other one to see if it helps.
What to do if sudo asks for a password you do not have
Your system asks for your own user password when you type sudo, not a separate root password. If you do not remember your user password, you cannot use sudo. Some systems are set up so that certain users do not need to type a password for sudo commands — this is configured by the system administrator and is not something you can change yourself.
If you are locked out of sudo and need root access, you will need to restart your computer and boot into recovery mode or single-user mode. The exact steps depend on your Linux distribution. On Ubuntu, you can hold Shift while the computer starts to see the boot menu, then choose "Advanced options" and look for a recovery mode option. This is a more complex process and usually only necessary if you have forgotten your password entirely.
Leaving the root shell and returning to your regular account
When you are finished with your root shell, type exit and press Enter. You will return to your regular user prompt, which ends with a dollar sign ($). At that point, you no longer have root permissions, and commands that need sudo will fail again if you try to run them without it.
If you open multiple root shells or nested command prompts, you may need to type exit more than once to get back to your starting point. Each time you type exit, you close one layer and move back one level.
Common mistakes and how to avoid them
The most common mistake is typing a command and forgetting to put sudo in front of it, then getting a "permission denied" error. If this happens, you can press the up arrow to bring back the last command, then press Home to move to the beginning of the line, type sudo , and press Enter. This is faster than retyping the whole command.
Another mistake is staying in a root shell longer than you need to. It is easy to forget that you have full permissions and accidentally delete or change something important. Open a root shell only when you actually need it, and type exit as soon as you are done. If you find yourself opening a root shell many times a day, consider whether you can use sudo for individual commands instead.
Frequently Asked Questions
Why does my system ask for a password when I type sudo?
Your system is confirming that you are actually you before giving you root permissions. This is a security feature — it prevents someone from walking up to your unlocked computer and running dangerous commands. The system remembers your password for a few minutes after you type it, so you will not have to type it again for every single sudo command.
Can I set up a root password instead of using sudo?
Yes, but most Linux distributions do not set up a root password by default because sudo is considered safer. If you want to set one, you can type sudo passwd root and follow the prompts. After that, you can type su (without sudo) to switch to the root user. However, this is not recommended for most users because it is easier to make mistakes when you have root access all the time.
What is the difference between root and sudo?
sudo lets you run a single command or open a shell with root permissions while staying logged in as your regular user. The root user is a separate account that has those permissions all the time. Using sudo is safer because you have to think about each command and type your password occasionally, which reminds you that you are doing something powerful.
Will opening a root shell break my system?
Opening a root shell itself does not break anything — it just gives you permissions. You break things by typing commands that delete files or change settings. If you are careful about what you type, a root shell is safe. If you are unsure whether a command is safe, look it up before you run it.
How do I know if I am in a root shell?
Look at your command prompt. If it ends with a hash symbol (#), you are in a root shell. If it ends with a dollar sign ($), you are a regular user. Some systems also change the color of the prompt to red or another color to make it obvious that you have root permissions.