Ubuntu root access usually starts with sudo, and a full root shell is available when you open one on purpose and close it when done.
Root is the account with full control over an Ubuntu system. That sounds handy, and it is. It also means one careless command can change permissions, remove packages, or wipe files in a hurry. That’s why Ubuntu pushes most people toward sudo instead of staying logged in as root all day.
If you’re trying to install software, edit a protected file, restart a service, or fix a system problem, you usually do not need a permanent root login. You need the right command, run at the right time, with a plain way back out. That’s the clean path, and it keeps your system easier to manage.
This article walks through the standard ways to get root access on Ubuntu, when each one fits, the commands that matter, and the mistakes that trip people up. You’ll also see how to turn on the root account password if you truly need it, then lock it again once the job is done.
What Root Means On Ubuntu
On Ubuntu, root is the superuser. That account can read, write, install, remove, and reconfigure nearly anything on the machine. Regular users do not get that reach by default. Administrative users borrow that reach with sudo, using their own password.
That setup gives you two wins. One, you do not have to sign in as root for routine admin work. Two, commands run through sudo are tied to your user account, which makes changes easier to trace. Canonical’s Ubuntu Server documentation points users toward this model and shows how the root account stays disabled unless you set a password for it. Ubuntu’s user management documentation lays out that behavior clearly.
So when people say “access root” on Ubuntu, they may mean one of three things:
- Run one command with admin rights.
- Open a temporary root shell for a short session.
- Enable the actual root account with its own password.
Those are not the same thing. Picking the right one keeps the system tidy and cuts down on nasty surprises.
How To Access Root Ubuntu From Terminal
The cleanest way to get root-level access on Ubuntu is to start with sudo. For one command, place sudo at the front:
sudo apt update
sudo systemctl restart nginx
sudo nano /etc/ssh/sshd_config
That method is great when you know the exact task. You stay in your normal shell, the command runs with elevated rights, and then you drop right back to your standard user.
If you need several root-level commands in a row, open a root shell instead of adding sudo to every line. The usual command is:
sudo -i
This starts an interactive login shell as root. Your prompt usually changes from a $ to a #. That visual cue matters. It reminds you that every command now has full control.
You may also see people use:
sudo su
That often works, though sudo -i is the cleaner Ubuntu-style choice. It opens a root login shell directly, without the extra hop through su. The Ubuntu manual pages also note that an interactive root shell can be opened with sudo -i, which matches common admin practice on current releases.
When A Single Sudo Command Is Better
Use one-off sudo commands when you are editing one file, restarting one service, checking one protected log, or installing one package. This keeps your admin actions narrow. There is less room to type the wrong command in the wrong directory.
It also helps when you are copying commands from documentation. Each command stands on its own, which makes it easier to stop and verify what it does before pressing Enter.
When A Root Shell Makes More Sense
A root shell fits when you are doing a short cluster of admin tasks, such as moving through protected directories, editing several config files, and restarting services after each change. The flow is smoother, and you are less likely to forget sudo on a line that needs it.
Still, this should be short-lived. Open it, finish the work, then leave it.
How To Exit Safely
To leave the root shell, type:
exit
You can also press Ctrl + D. Once the prompt returns to your regular user, you are back in a safer working mode.
Commands That Give Root Access On Ubuntu
These are the commands most people actually need. They look similar at a glance, though they behave a bit differently.
Table 1: Common Root Access Commands On Ubuntu
| Command | What It Does | Best Time To Use It |
|---|---|---|
sudo command |
Runs one command with root privileges. | Package installs, service restarts, file edits. |
sudo -i |
Opens an interactive root login shell. | Several admin tasks in one short session. |
sudo su |
Starts su through sudo and lands in a root shell. |
Older habit on mixed Linux setups. |
su - |
Switches to the root account with a root password. | Only after the root account has been enabled. |
sudo passwd root |
Sets a password for the root account. | Rare cases when direct root login is required. |
sudo passwd -l root |
Locks the root account password again. | After temporary direct root access is no longer needed. |
sudo -k |
Clears the cached sudo credential timestamp. | When you want a fresh password prompt right away. |
whoami |
Shows the current user name. | Checking whether you are root or a regular user. |
If you are ever unsure where you stand, run whoami. If the output is root, treat every command with extra care.
How To Enable The Root Account On Ubuntu
By default, Ubuntu does not ask you to set a root password during installation. That keeps direct root sign-in out of the way. If you still need the actual root account, you can enable it by assigning a password:
sudo passwd root
You will first enter your own password, then type the new root password twice. After that, the root account can be used with su -:
su -
At that point, Ubuntu asks for the root password you just created. This is the old-school way to switch to root, and it works fine when there is a real need for direct root authentication.
Still, this path should be reserved for narrow cases, such as certain recovery steps, scripts built around direct root login, or environments where another admin process expects a root password. On ordinary desktop and server work, sudo is the better fit.
The Ubuntu documentation spells out both commands: sudo passwd to set the root password and sudo passwd -l root to lock it again after use. That lock step matters because it returns the machine to Ubuntu’s safer default state.
How To Disable The Root Password Again
Once you are done with the task that needed direct root access, lock the root account:
sudo passwd -l root
This does not remove the account itself. It just prevents password-based root login. For many Ubuntu users, that is exactly where things should stay.
How To Check Whether You Already Have Root Access
A lot of confusion comes from mixing up “I can use sudo” with “I am logged in as root.” They are close cousins, not twins.
Run this command:
whoami
If it prints your username, you are not root, even if you are allowed to run sudo. If it prints root, you are already in a root shell.
You can also test your sudo rights with a harmless command such as:
sudo -v
That checks and refreshes your sudo credentials without changing system files. If your account is not in the sudo group, Ubuntu will tell you.
Typical Jobs That Need Root On Ubuntu
Not every system task needs a root shell. Many need root privileges for one command and nothing more. These are common cases:
- Installing or removing packages with
apt. - Editing files under
/etc. - Restarting services with
systemctl. - Reading protected logs under
/var/log. - Changing file ownership with
chown. - Managing users and groups.
On the other hand, work inside your home directory, plain file edits, code projects, and routine browsing do not need root. Running those as root is where accidents creep in.
Table 2: Best Choice For Different Ubuntu Admin Tasks
| Task | Best Access Method | Why It Fits |
|---|---|---|
| Install one package | sudo apt install |
Keeps admin rights tied to one command. |
| Edit one config file | sudo nano or sudoedit |
Narrow access, less room for mistakes. |
| Many admin changes in one session | sudo -i |
Smoother flow for short bursts of system work. |
| Legacy workflow that expects root password | sudo passwd root then su - |
Only if direct root authentication is required. |
| Finish admin work and return to safety | exit |
Closes the root shell right away. |
Mistakes That Cause Trouble Fast
The biggest mistake is staying in a root shell longer than needed. Once you are root, commands that would normally fail can change the whole system. A typo in rm, mv, or chmod can turn into a long repair job.
Another common slip is editing files with the wrong ownership outcome. If you open and save user files as root, the file may end up owned by root. Then your normal account cannot edit it later without more admin work.
One more trap: enabling the root password and forgetting to lock it again. If you only needed it for a short admin task, shut that door after the task is done.
The Ubuntu sudoers manual page also makes clear that sudo policies control who may run commands as root and under what conditions. That is why editing sudo privileges should be done with care, and with visudo when the sudoers file itself is involved.
A Safer Routine For Root Work
If you want a habit that works well on Ubuntu, use this routine:
- Start as your normal user.
- Run one command with
sudowhen one command is enough. - Use
sudo -ionly when several root-level commands truly belong together. - Run
whoamiif you are unsure which account you are using. - Type
exitas soon as the admin task is finished. - Lock the root password again if you enabled it for a short-term need.
That pattern is simple, readable, and hard to mess up. It also lines up with how Ubuntu expects administrative work to be done.
Final Notes On Accessing Root In Ubuntu
If your goal is to get system-level control, start with sudo. That is the standard Ubuntu path. It gives you root privileges without turning root into your everyday account. When you need a fuller session, sudo -i gives you a root shell you can enter and leave cleanly.
If you must enable the root account itself, do it with intention, use a strong password, complete the job, and lock it again. That keeps direct root login from hanging around longer than needed.
Most of the time, the trick is not learning a dozen commands. It is knowing which level of access fits the job in front of you. Get that right, and Ubuntu admin work feels a lot less risky.
References & Sources
- Canonical.“User management – Ubuntu Server.”Shows that Ubuntu uses sudo for admin work, explains how to enable the root account, and shows how to lock the root password again.
- Ubuntu Manpage Repository.“sudoers — default sudo security policy plugin.”Details how sudo privileges are governed and supports the caution around editing sudo access rules.
