How to use sudo command to increase permissions under Linux system

  

As a Linux system administrator, or just getting started, sudo commands must be known, then what is the sudo command? What is the role, let's get to know it with Xiaobian.

sudo is an order that governs everything. It literally means “superusers can do it!” "super user do!) For Linux system administrators or advanced users, it is one of the most important commands. Have you ever had the experience of trying to run a command in the terminal, but you end up with “look for access”? This is the command you need! But as the saying goes, the greater the power, the greater the responsibility! Sudo is much better than logging in as the root user or using the su “switch user” command. Please read it patiently and see what sudo can do for you!

sudo: What is it used for?

So, what can sudo actually do? If you prefix the Linux command with the “sudo” prefix, it will run the command with elevated privileges. The ability to perform certain administrative tasks requires elevated privileges. One day, you might want to run a LAMP (Linux Apache MySQL PHP) server and manually edit the configuration file. You may also want to restart or reset the Apache web server or other service daemons. You even need elevated privileges to shut down or restart your computer. “ Hey, who closed this machine? ”

If you are familiar with Windows, sudo is very similar to the Windows User Account Control (ACL) dialog that pops up when you try to handle any important operations, just not as friendly as the latter. In Windows, if you try to perform an administrative task, the dialog asks if you want to continue (“ Are you sure you want to run the program you just clicked? & rdquo;) and then perform the task. On a Mac machine, a security dialog pops up asking you to enter your password and clicking “OK”.

And Linux is more dramatic. Some operations can be quite weird without proper permissions. The important configuration file you are editing may not be able to save the content correctly. The program you installed is probably a refusal to run. The excellent source code that you have downloaded and wants to compile cannot be compiled. If you are unlucky, you will even see "Deny access" or another error message. Everything you worry about most becomes a reality, but all you have to do is request permission! That's why we should always ask for superuser privileges when doing something like this:

sudo reboot

Take a look at this screenshot if we didn't first use sudo to boost permissions.

first of all, we try to use the restart command to restart the system: what happens. The order did not mention: "Must be a super user". Then we tried to restart with sudo. Sudo requires you to provide a user password. Please note: it requires you to provide your password instead of the root password. Finally, we see that the broadcast information of the system will now be restarted. Sudo is like a magical command that will make magical commands.

Why sudo better than the other way?

sudo is the best and safest way to improve permissions. Let's take a look at another way to improve permissions. As a switch user command, <;su” will ask you to enter the root password and give you a superuser prompt, indicated by the # symbol. This # symbol means "danger!" You have already logged in as the root user! ” Your first order may have been successfully executed. But once you forget, you will continue to log in as the root user. If you miss a word, you are finished! You cleared the entire hard drive instead of clearing the pirated mp3 file you downloaded. Your web server and home company are gone! If it is sudo, you have to type “sudo” before each command. Therefore, you don't have to remember to switch back to the regular user mode, so there will be fewer accidents.

Suderos file

This file is the basis of sudo. It controls who can use the sudo command to gain elevated privileges. It is usually located in /etc/sudoers. The most effective and safe way to edit this file is to use the visudo command. This command will launch the vi editor with elevated privileges so you can edit and save the file. It also locks the file on the sudoers file so that others can't edit the file. Once you've finished editing, it analyzes the file for any simple errors. Editing a sudo file is much safer than just using any old text editor.

This file contains many parameters. You can specify which users or users help which commands can be executed. We are going to grant ourselves access to sudo, just add it at the bottom:

username ALL=(ALL) ALL //grant sudo access to the user "username”%wheel ALL=(ALL) ALL //Grant sudo access to all users belonging to the wheel user group

Now the specified username will be able to use all root privileges. You can also allow a user or group of users to have sudo access to a particular service or server instead of the ALL parameter, but that's another topic.

Several Options

As with any great command, there are several great options for sudo to handle more transactions.

sudo -b will run commands in the background. This is useful for commands that display a lot of real-time output.

sudo -s will run the shell specified with elevated privileges, giving you a # prompt (don't forget to quit!)

sudo su - will make you the root user and load Your custom user environment variables.

Is there any use now?

When we want to run important tasks, sudo provides secure elevated privileges. Among Ubuntu users, it is perhaps the most widely used and most powerful command, as it has become the preferred method in this release. Since you have such a big right, be sure to be safe when running commands! There is no su-undo cancellation command in the world!

The above is the purpose of the Linux sudo command. Adding sudo in front of the Linux command can increase the permissions to run the command. Simple and practical, have you learned?

Copyright © Windows knowledge All Rights Reserved