Linux system administrator commands to know: sudo

Source: Internet
Author: User

For Linux system administrators or advanced users, Sudo is one of the most important commands necessary. sudo provides secure elevation of privilege when we want to run important tasks. Please read this article patiently and see what sudo can do for you.

sudo is a command that governs everything. It literally means "super user can do it!" "(Super User do!) is one of the most important commands necessary for Linux system administrators or advanced users. Have you ever had this experience: trying to run a command in a terminal and encountering "Access Denied"? This is the command you need! But the greater the power, the greater the responsibility! Sudo is much better than logging in as a 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 any linux command with the word "sudo", it will run the command with elevated privileges. Perform certain administrative tasks that require elevated privileges. Someday, 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 daemon. You even need elevated permissions to shut down or restart the computer. "Hey, who shut down this machine?" ”

If you are familiar with Windows,sudo and when you try to handle any important action, the Windows User Account Control (ACL) dialog box that bounces out is very similar, but 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?"). ") to perform the task later. On the Mac machine, a security dialog box will pop up asking you to enter your password and click "OK".

And Linux seems more dramatic. Without proper permissions, some operations can be quite bizarre. The important profile you are editing may not be able to save the content correctly. The program you installed might be a denial of operation. The piece of good source code that you have downloaded and want to compile is not compiled. If you're unlucky, you'll even see an "access Denied" or another error message. All the things you worry about are turned into reality, but all you have to do is ask for permission! That's why we should remember to request Superuser permissions in advance when doing something like this:

sudo reboot

Look at this screen to see what happens if we don't elevate permissions with sudo first:

First, we use the restart command to try to restart the system. The command mentions: "Must be superuser." Then we try to restart with sudo. sudo requires you to provide a user password. Please note: It requires you to provide your password, not the root password (as long as the delegation of authority to the user is not allowed to tell them the root password, sudo reduces the chances of the user delegating the operation by hand). Finally, we see the broadcast information that indicates that the system will now be restarted. Sudo is like a magical command that sends out magical instructions.

Why is sudo better than the other way?

sudo is the best and safest way to elevate permissions. We might as well look at another way to elevate permissions. As a switch user command, "su" will ask you to enter the root password and give you a super user prompt, denoted by the # symbol. This # symbol means "Danger!" You are logged in as a root user! "The first command you gave may have been executed successfully. But once you forget, you will continue to log in as the root user. If you hit a wrong word, you're screwed! Instead of erasing the pirated MP3 file you downloaded, you cleared the entire hard drive. Your Web server and home company are all gone! if it is sudo, you will have to enter "sudo" before each command. As a result, you don't have to remember to cut back into regular user mode, so there will be fewer accidents.

Suderos file

This document is the foundation 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 secure way to edit this file is to use the Visudo command. This command launches the VI Editor with elevated privileges so that you can edit and save the file. It also gives the file lock on the sudoers file so that no one else can edit the file. Once you have completed the editing work, it will parse the file to find out if there are any simple errors. Editing sudo files is much safer than just using any old text editor.

The file contains many parameters. You can specify which users or which user help can execute which commands. We're going to give ourselves permission to access sudo, so just add it at the bottom:

Username  all= (All)   //%wheel    all= (All)   //  Grant sudo access to all users who belong to the wheel user group

The user name you specify now will be able to use all of the root permissions. 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 good command, there are several great options for sudo to handle more transactions.

    • Sudo-b will run the command in the background. This is useful for commands that display many real-time output content.
    • Sudo-s will run a shell that is specified with elevated privileges, providing you with a # prompt (Don't forget to exit!). )
    • sudo su-will make you a root user and load your custom user environment variables.

Did you use it now?

sudo provides secure elevation of privilege when we want to run important tasks. Among Ubuntu users, it may be the most widely used and most powerful command, as it has become the preferred method in this release. Since you have so much power, be sure to be safe when you run your commands! There is no su-undo in the world to revoke orders!

Linux system administrator commands to know: sudo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.