Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the root user in Ubuntu

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces what the root users in Ubuntu are, which can be used for reference by interested friends. I hope you can learn a lot after reading this article. Let's take a look at it with you.

What is a root user? Why is it locked in Ubuntu?

In Linux, there is a super user called root. This is the Super Admin account, which can do anything and use everything in the system. It can access any file and run any command on your Linux system.

The greater the ability, the greater the responsibility. Root users give you complete control of the system, so it should be used with caution. Root users can access system files and run commands that change the system configuration. Therefore, a wrong command may break the system.

This is why Ubuntu and other Ubuntu-based distributions lock in root users by default to save you from unexpected disasters.

For your daily tasks, such as moving files in your directory, downloading files from the Internet, creating documents, etc., you don't need to have root permission.

Metaphorically speaking, to better understand it. Suppose you want to cut a fruit, you can use a kitchen knife. Suppose you want to cut down a tree, you have to use a saw. Now, you can use a saw to cut fruit, but that's unwise, isn't it? _

Does this mean that you can't be a root user in Ubuntu or use root privileges to use the system? No, you can still have root access with the help of sudo (explained in the next section).

Important: root user rights are too powerful for general tasks. This is why it is not recommended to use root users all the time. You can still use the root user to run special commands.

How do I run commands like a root user in Ubuntu?

Image Credit: xkcd

For some special tasks of the system, you will need root permission. For example. If you want to update Ubuntu from the command line, you cannot run the command as a regular user. It will give the error that the permission was denied.

Apt updateReading package lists... DoneE: Could not open lock file / var/lib/apt/lists/lock-open (13: Permission denied) E: Unable to lock directory / var/lib/apt/lists/W: Problem unlinking the file / var/cache/apt/pkgcache.bin-RemoveCaches (13: Permission denied) W: Problem unlinking the file / var/cache/apt/srcpkgcache.bin-RemoveCaches (13: Permission denied)

So, how do you run commands like root users? The simple answer is to add sudo before the command to run like a root user.

Sudo apt update

Ubuntu and many other Linux distributions use a special program mechanism called sudo. Sudo is a program that uses root users (or other users) to control access to running commands.

In fact, sudo is a very versatile tool. It can be configured to allow a user to run all commands like a root user, or just a few commands. You can also be configured to run commands using sudo without a password. This topic is rich in content, and perhaps I will discuss it in detail in another article.

For now, you should know that when you install Ubuntu, you have to create a user account. This user account works as an administrator on your system, and according to the default sudo policy in Ubuntu, it can run any command on your system with root privileges.

The problem with sudo is that you don't need a root password to run sudo, but you need your own password.

And that's why when you run a command using sudo, you are asked to enter the password of the user who is running the sudo command:

[email protected]: ~ $sudo apt update [sudo] password for abhishek:

As you can see in the above example, abhishek is trying to use sudo to run the apt update command, and the system asks for the password of abhishek.

If you are not familiar with Linux at all, you may be surprised that nothing happens on the screen when you start typing your password on the terminal. This is quite normal because, as the default security feature, nothing is displayed on the screen. Not even an asterisk (*). Enter your password and press enter.

Important: to run the command like a root user in Ubuntu, add sudo before the command. When asked to enter a password, enter the password of your account. When you type the password on the screen, you can't see anything. Please continue to enter your password and press enter.

How to become a root user in Ubuntu?

You can use sudo to run commands like root users. However, in some cases, you have to run some commands as root, and you always forget to add sudo before the command, so you can temporarily switch to root.

The sudo command allows you to simulate a shell logged in by a root user, using this command:

Sudo-I [email protected]: ~ $sudo-I [sudo] password for abhishek: [email protected]: ~ # whoamiroot

You will notice that when you switch to root, the shell command prompt changes from $(dollar sign) to # (pound sterling sign). I made a (bad) joke that the pound is stronger than the dollar.

Although I have shown you how to become a root user, I must warn you that you should avoid using the system as a root user. After all, it has reasons to prevent you from using root users.

Another way to temporarily switch to root is to use the su command:

Sudo su

If you try to use the su command without sudo, you will encounter a "su authentication failure" error.

You can use the exit command to return to a normal user.

How does exit enable root users in Ubuntu?

Now you know that root users are locked by default in Ubuntu-based distributions.

Linux gives you the freedom to do whatever you want on the system. Unlocking root users is one of these freedoms.

If for some reason you decide to enable root users, you can do so by setting a password for them:

Sudo passwd root

Again, root users are not recommended, and I don't encourage you to do so on the desktop. If you forget your password, you will not be able to change the root password in Ubuntu again. (LCTT translation note: can be modified through single-user mode. )

You can lock the root user again by removing the password:

Sudo passwd-dl root thank you for reading this article carefully. I hope the article "what are root users in Ubuntu" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report