Linux system command sudo use detailed explanation

  

“Sudo” is a very useful tool on the #Llinux# platform, which allows system administrators to assign some reasonable "rights" to ordinary users, let them perform some only Tasks that superusers or other privileged users can accomplish, such as running commands like restart, reboot, passwd, or editing some system configuration files, which not only reduces the number of logins and management time for root users, but also improves them. System security.

Sudo is a command 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”? As the so-called power is greater, the greater the responsibility, log in with the root user, or use the su “switch user” command, sudo is much better.

If you prefix the linux command with the sudo” prefix, it will run the command with elevated privileges and perform elevated tasks for certain administrative tasks.

If you are familiar with Windows
system sudo and when you try to handle any important operations, the pop-up Windows User Account Control (ACL) dialog is very similar, 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;) to confirm the task. On the Apple Mac Computer
, a security dialog will pop up asking you to enter your password. If you don't have the proper permissions under Linux, some operations will be quite weird. Which important configuration file you edit may not save the content properly. The program you installed may refuse 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.

Using sudo is the safest way to increase permissions. Let's take a look at another way to improve permissions. Switching user commands “su” will ask you to enter the root password and give you a superuser prompt, indicated by the # symbol, this # symbol means "dangerous!" You have logged in as the root user. ”

Suderos file

This file is the basis of sudo, which controls who can use the sudo command to get elevated privileges, usually located in /etc/sudoers. An effective and secure way is to use the visudo command. This command launches 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, and if you finish editing it will analyze the file for simple errors. Editing sudo files with visudo is much safer than just using any old text editor.

The sudoers file contains a number of parameters that specify which users or groups of users can execute which commands. We are going to grant ourselves access to sudo as long as it is added at the bottom: username ALL=(ALL) ALL //for the user “username” Grant sudo access%wheel ALL=(ALL) ALL //Grant sudo access to all users belonging to the wheel user group Now the specified username can use all root privileges.

Linux Commands Several options for sudo

  • 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 you Those custom user environment variables.

    Features of the Linux command sudo

    The role played by sudo is destined to be extra cautious in terms of security, otherwise it will lead to illegal users gaining root privileges, and it will also take into account Sexuality allows system administrators to use it more efficiently and conveniently. The sudo design is designed to give users as little permission as possible but still allow them to complete their work. So sudo has the following characteristics:

  • sudo can limit the specified user to run certain commands on the specified host.
  • Sudo can provide logs, faithfully record what each user does with sudo, and can pass logs to a central host or log server.
  • sudo provides system administrators with configuration files that allow system administrators to centrally manage user permissions and hosts used. The default location is /etc/sudoers.
  • sudo uses a timestamp file to complete a system similar to "checking". When the user executes sudo and enters the password, the user gets a default ticket with a lifetime of 5 minutes (the ticket can be changed at compile time). After the timeout, the user must re-enter the password.

    Linux Commands sudo Common Parameters

  • sudo -h Help List usage and exit.
  • sudo -V Version Display version information and exit.
  • sudo -l List Lists the commands that the current user can execute. This option is only available to users in sudoers.
  • sudo -u username| #uid User Executes the command as the specified user. The latter user is in addition to root, which can be a username or #uid.
  • sudo -k Kill Clear the time on the "admission volume" and re-enter the password the next time you use sudo.
  • sudo -K Sure kill is similar to -k, but it also tears up the "admission volume", which is to delete the timestamp file.
  • sudo -b command Background Executes the specified command in the background.
  • sudo -p prompt command Prompt can change the prompt for asking for a password, where %u will be replaced with the user account name and %h will display the host name. Very user-friendly design.
  • sudo -e file Edit is not a command, but a modified file is equivalent to the command sudoedit.

    ~end~

  • Copyright © Windows knowledge All Rights Reserved