At times, there are certain operations in Ubuntu that must be performed with elevated privileges referred to as the “Sudo” privileges. The Sudo command in Ubuntu is used whenever you need administrative privileges to perform an operation or run another command. Sudo stands for “Super User Do”. In this guide, we will try to understand the Sudo command in Ubuntu.
Why is the Sudo Command Considered a Safe Option in Ubuntu?
There is another command in Linux i.e. “su”. It stands for “switch user”. Now you might be thinking that we can easily use the “su” command to switch to the Root user account whenever we wish to run anything with administrative privileges. Then why do we need the Sudo command in the first place? Well, the “su” command does help in switching the user and using this command, you can indeed switch to the Root user and perform an operation with escalated privileges. However, you need to be extra careful. Because not all the operations in Ubuntu need to be performed with Root user privileges. Therefore, after performing the desired operation, you must switch back to the normal user. Otherwise, you will just keep on doing everything with elevated privileges which will render your system at a security risk. In this situation, the Sudo command is the safest option because it just momentarily switches the user for only a single operation. Therefore, you will not need to switch back to the normal user after executing the Sudo command in Ubuntu.
The Equivalent of the Linux Sudo Command in Windows:
The equivalent of the Linux Sudo command in the Windows operating system is the “Run as Administrator” option that can easily be accessed by right-clicking on any program in Windows that you wish to run with elevated privileges as shown in the image below:
Using the Sudo Command on Ubuntu:
Now, we will show you a scenario with the help of which you will easily be able to understand the usage of the Sudo command in Ubuntu.
Step # 1: Checking the Help Manual of the Sudo Command in Ubuntu:
First, we would like to take a look at the help manual of the Sudo command to understand its usage well. For that, we have to run the following command:
$ sudo –h
This command will not only display the general syntax of the Sudo command but also all the options that can be used with it as shown in the image below:
Step # 2: Running a Command without Sudo Privileges:
Now, we will try to run the Update command in Ubuntu without using the Sudo command in the following manner:
$ apt-get update
You cannot run the Update command without the Sudo privileges in Ubuntu. Because of this, you will get the “Permission Denied” error upon execution and your system will not be updated as shown in the image below:
Step # 3: Using the Same Command with the Sudo Command:
To fix this error, we will now run the same Update command with the Sudo command as follows:
$ sudo apt-get update
Now, when you will run this command with the Sudo privileges, you will be asked to enter the Sudo password as shown in the image below:
Once you will enter the Sudo password correctly, this command will immediately start executing which means that now, your Ubuntu system will be updated successfully.
This guide thoroughly explained all the important aspects of using the Sudo command in Ubuntu. We first talked about the purpose of this command in Ubuntu after which we shared with you the reason behind this command being the safest option in Ubuntu. We also discussed the equivalent option of this command in Windows. Finally, we shared with you a scenario that depicted the importance of the Sudo command in Ubuntu. Now, you will probably be in a good position to understand how the Sudo command works in Ubuntu.