Contents...
Sudo command in Linux. There are a large number of command that one can use in the terminal, and one command to rule them all. In fact, one of the most important commands out there is the sudo command. In most instances, when we want to alter the system in any way, such as installing a program or overwriting a key file, we typically have to include the sudo command at the beginning. In this tutorial, we will review the sudo command.
The sudo command
Sudo stands for either “substitute user do”, or “super user do”. For security reasons, not everyone on the system has root access, but as a superuser, you do have root access. The sudo command is used when we wish to execute a particular command as a superuser, or another user. In other words, if as a user we do not have enough privileges to execute a particular task, but that another user does or that the superuser does, then, we can use the sudo command to temporarily alter our privileges. However, in order to gain root access, you will be prompted for authentication with a password, the administrative password. In the event that you do input the sudo password, the linux system, will for the following 15 minutes, remember the password. What that implies is that it will not prompt for the password for the next 15 minutes, but after the 15 minutes are up, you will be prompted for authentication once more should you wish to use the sudo command. Of course you can modify this set time by modifying the file /etc/sudoers.
In fact, most modifications to the sudo command are initiated in the /etc/sudoers file. However, to edit the /etc/sudoers file, you need to to be root, and to type the following:
sudo visudo -f /etc/sudoers
Although sudo and su are used as command line, there is a graphical version that you can use called gksudo. However, it has been deprecated in the later versions of Ubuntu.
The redo command
Sudo is typically used to alter privileges, but it has another functionality. Sudo followed by two exclamation points functions as the redo command.
sudo !!
Suppose that you type out an expression that requires root privileges, but that you forget to write sudo in front of it. What you’ll get is a “Permission denied” error. What this means is that you have to log out of the file, and redo the expression with a sudo in front of it. This is where the expression “sudo !!” comes in. Instead of writing out the entire expression again, you can just type “sudo !!” which will redo the previous expression with a sudo attached to it.
For example, if file.txt has permission 700, and that you try the following:
nano secretfile.txt
You’ll get a “Permission denied” error! And the way to fix this error is by typing sudo and entering the password before the command can be executed. So instead of re-writing the whole thing, we can just write the following:
sudo !!
Here, “sudo !!” is equivalent to “sudo nano secretfile.txt”. Basically, it’s equivalent to the previous expression with a sudo in front of it.
Although all linux commands are worth knowing, there is one command that you cannot survive without on the linux system, and that’s the sudo command. The sudo command is used to alter our privileges temporarily. You can also use the sudo command as a redo command if two exclamation points are attached to it.
Happy Coding!
FAQs
What does sudo stand for?
Sudo stands for either “substitute user do”, or “super user do”.
What does sudo!! do?
Sudo followed by two exclamation points functions as the redo command.
Where do we edit the sudo file?
Most modifications to the sudo command are initiated in the /etc/sudoers file. However, to edit the /etc/sudoers file, you need to to be root, and type: sudo visudo -f /etc/sudoers
What is sudo used for?
For security reasons, not everyone on the system has root access, but as a superuser, you do have root access. The sudo command is used when we wish to execute a particular command as a superuser, or another user.
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment