What is "root" and how can I become it? [duplicate]
When I ran a command, I got the following error:
You need to be root to perform this command.
What is root
and how can I become it?
What is "root"?
root is a user existing on every Linux system.
To be more precise, it is a special user - the super user!root
is the only user that has privileges to do everything.
In contrast to the two types of user accounts you can create (administrator users and restricted users), it exists by default and can neither be renamed or deleted. Usually, logging in as root
is disabled for security reasons.
You may think that your admin user is the most powerful account on your machine and may do everything, but that is wrong. Simplified and in general, your admin user is almost equal to a restricted user in permissions. It also only has writing permissions in its own home folder and also may not change system wide settings.
However, the admin users have one special and important privilege:
How to become "root"?
As logging in as root is prohibited on Ubuntu per default, there has to be another way to become root in order to be able to perform important system wide administrative tasks.
The sudo
command<-- (abbreviation for "Super User DO ...")
Administrator user accounts have the permission to use the sudo
command to execute a single command as root/with root privileges.
It is simple. Just write sudo
before every terminal command that needs special elevated permissions to run and execute it. It will show you a prompt and ask for a password like this (my username is bytecommander
):
[sudo] password for bytecommander:
Note that you have to enter the password of your own admin account and not the (by default not existing) root user's password. It is also configured to only ask once every 15 minutes for your password, so the second invocation of sudo
will run the command immediately. However, if you close the terminal window, the sudo ticket is also reset. Furthermore is it important for you to know that there will be no display output when you type the password, not even stars (*) will appear to symbolize the entered characters. Just type it and hit Enter.
Let me give you an example on how/when to use sudo:
-
apt-get
is the command-line tool to run software updates and install new packages. This affects the whole system and therefore requires root permissions. Therefore, whenever we need to invokeapt-get
, we have to do this withsudo
:sudo apt-get install vlc
would for example install the famous media player VLC (after asking for your password, if you did not enter it in the current terminal window within the last 15 minutes). If we ran the command as normal user without sudo (apt-get install vlc
only), it would result in this error:
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
How to proceed with graphical applications instead of terminal commands?
Sometimes you need to run a graphical application (such as e.g. the Files manager, a special editor or an additional tweak tool) with root privileges. In this case, please do not use sudo
, as this is only for terminal commands. For several reasons I don't want to discuss here, it may lead to severe problems (see this answer for further explanations)...
So for graphical applications, there are other commands which are safer to run GUI apps and which provide a graphical popup-window to request your password instead of a terminal window. Those are mainly gksu
and gksudo
. Experts are arguing which of them is to prefer, but for the normal Ubuntu user, both can be taken equally. The syntax is the same as with sudo
. For example, we can run the file manger Nautilus
with root privileges by:
gksudo nautilus
root is the user name or account that by default has access to all commands and files on a Linux or other Unix-like operating system. It is also referred to as the root account, root user and the superuser.
So there will arise certain cases when you will have to be logged in as root user to run those commands. Do not worry it is simple.
By default, the root account password is locked in Ubuntu. This means that you cannot log in as root directly or use the su command to become the root user. However, since the root account physically exists it is still possible to run programs with root-level privileges. This is where
sudo
comes in - it allows authorized users to run certain programs as root without having to know the root password.
This means that in the terminal you should use sudo for commands that require root privileges; simply prepend sudo to all the commands you need to run as root. You will be prompted for a password when you sudo. Just remember, when sudo asks for a password, it needs YOUR USER password, and not the root account password.
When using sudo, your password is stored by default for 15 minutes. After that time, you will need to enter your password again.
Your password will not be shown on the screen as you type it, not even as a row of stars (******). It is being entered with each keystroke!
For more info please refer: https://help.ubuntu.com/community/RootSudo