SUDO commands in Linux for beginners
Sudo Command in Linux : Sudo, the only command to govern them all. It is synonymous with “superuser”. Pronounced “sue dough” As a Linux system administrator or advanced user, it is one of the most important commands in your arsenal. Have you ever tried to execute a command on the terminal to be granted “Access Denied?” Well this is the command for you! But with great power comes a great responsibility! It is much better than logging in as root or using the command “switch user”. Keep reading to see what sudo can do for you!
SUDO: What is it for?
So, what does sudo really do? If you prefer “sudo” with any Linux command, it will execute that command with elevated privileges. High privileges are required to perform certain administrative tasks. It is possible that some day you want to run a LAMP server (Linux Apache MySQL PHP) and have to manually edit your configuration files. You may also need to restart or restart the Apache web server or other service daemons. It even needs elevated privileges to shut down or restart the computer. “Hey, who turned this thing off?”
If you are familiar with Windows, it is very similar to the Windows User Account Control dialog box that appears when you try to do something important, but not so friendly. On Windows, if you try to perform an administrative task, a dialog box asks you if you want to continue (“Are you really sure you want to run the program you just clicked on?”). Then the task is done. On a Mac, a security dialog box appears and you are asked to enter your password and click OK.
It’s more of a dramatic story in Linux. Things can behave quite strangely without the proper permissions. It is possible that the important configuration file you were editing is not saved correctly. A program that you installed may simply refuse to run. That impressive source code that you downloaded and you need to compile, you will not. You may even be lucky to receive an “Access Denied” or other friendly error message. All your worst fears have come true, but all you needed to do was ask for permission! That’s why we want to remember to request superuser permissions in advance like this:
restart of sudo
See what happens in this screenshot if we do not first raise our permissions with sudo:
First we use the reboot command to try to restart the system. The command fails citing: “must be superuser”. So we try with sudo restart. Sudo asks for your user password. Note that you are requesting your password, not the root password. Finally we see the transmission message that the system will restart now. Sudo is like saying the magic word. It could also be called opensesame or abracadabra or even bippityboppitybacon.
Why is it better than the alternative?
Sudo is the best and safest way to elevate privileges. Let’s look at another way of doing things. The user change command, “su” will ask for the root password and will give you a superuser message, represented by the # symbol. That symbol # means “DANGER! YOUR RECORD IN THE ROOT!
The first command you issue can go well. But your forgetfulness will keep you connected as root. A bad typo and BAM! You deleted all the hard drive instead of that fake mp3 that you downloaded. The cat decides to lie down on your nice and warm laptop. FAGOT! Your web server and home business are gone! With the sudo command, you must enter “sudo” before each command. Therefore, you do not have to remember to return to normal user mode, and fewer accidents will happen.
The file of the Suderos
This file is the sordid sordid of sudo. Controls who can use the sudo command to obtain elevated privileges. It is usually found in / etc / sudoers. The best and safest way to edit this file is using the visudo command. This command will start the vi editor with elevated privileges so you can edit the file and save it. It will also put a file lock in the sudoers file so that nobody else can edit it. Once you have finished editing it, it will scan the file for simple errors. It is a much safer way to edit the sudo file than using an old text editor.
This file contains many parameters. You can specify which users of which groups can perform which commands. We are simply going to give us access to sudo by adding:
Username ALL = (ALL) ALL // gives the user "username" sudo access
% wheel ALL = (ALL) ALL // Gives access to all users belonging to the group of wheels sudo
in the background. Now the specified username can use all root privileges. You can also allow a user or group to have access only to specific services or servers in replacement of the ALL parameter, but that is a topic for another day.
Like any good command, there are some ingenious options for doing sudo, do more!
sudo -b will execute the command in the background. This is useful for commands that display a large number of results as they are executed.
sudo -s will execute the specified shell with elevated privileges, giving it the # prompt (do not forget to leave!)
sudo its it will become the root user and load its custom user environment variables.
Get it now?
Sudo gives us elevated privileges safe when we want to execute important commands. It could be THE most used and powerful command among Ubuntu users, since it has become the preferred method in that distribution. Now that you have the power, be sure to be sure when you issue your commands! There is no su-undo!
If you are looking for red hat enterprise linux training please contact us on firstname.lastname@example.org. Innovative Technology Solutions is Red Hat Training Partner in India & ITS is offering a number of Red Hat Certification courses in multiple cities in India.