Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use sudo command in Linux system

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces how to use the sudo command in the Linux system, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Sudo: what's its use?

So what can sudo actually do? If you prefix any Linux command with the word "sudo", it will run the command with elevated privileges. Privileges that need to be elevated to perform certain administrative tasks. One day, you may want to run a LAMP (Linux Apache MySQL PHP) server and edit the configuration file manually. You may also have to restart or reset the Apache Web server or other service daemon. You even need elevated privileges to shut down or restart the computer. "Hey, who turned off this machine?"

If you are familiar with Windows,sudo, the pop-up Windows user account Control (ACL) dialog box is very similar to when you try to handle any important operation, but not as friendly as the latter. In Windows, if you try to perform an administrative task, the dialog box asks if you want to continue ("are you sure you want to run the program you just clicked on?" ) then perform the task On the Mac machine, a security dialog box pops up, asking you to enter your password and click OK.

The Linux side is even more dramatic. Without proper permissions, some operations can seem pretty weird. The important configuration file you are editing may not save the contents correctly. The program you installed may simply refuse to run. The excellent source code that you have downloaded and want to compile cannot be compiled. If you are unlucky, you may even see "access denied" or another error message. Your worst fears have come true, but all you have to do is ask for permission! This is why we should remember to ask for superuser permissions in advance when performing operations such as the following:

Sudo reboot

In this screenshot, let's see what happens if we don't upgrade our permissions with sudo first:

First, we use the restart command to try to restart the system. The command does not mention: "must be a superuser." Then we try to restart it with sudo. Sudo requires you to provide the user's password. Please note: it requires you to provide your password, not the root password. *, we see a broadcast message indicating that the system will be restarted now. Sudo is like a magic command, giving out magic instructions.

Why is sudo better than the other way?

Sudo is the best and most secure way to elevate privileges. Let's take a look at another way to elevate privileges. As a command to switch users, "su" will ask you to enter the root password and give you a superuser prompt, indicated by the # symbol. The # symbol means "danger! you have logged in as a root user!" The orders you issued may have been successfully carried out. But once you forget, you will continue to log in as root. If you type one wrong word, it's over! You erased the entire hard drive instead of the pirated mp3 file you downloaded. Your Web server and home company are all gone! If it's sudo, you have to type "sudo" before each command. Therefore, you don't have to remember to switch back to regular user mode, so there will be fewer accidents.

Suderos file

This file can be said to be the basis of sudo. It controls who can use the sudo command to gain elevated privileges. It is usually located at / 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 locks the sudoers file so that no one else can edit the file. Once you have finished editing, it analyzes the file to see if there are any simple errors. Editing sudo files is much safer than just using any old text editor.

This file contains many parameters. You can specify which users or users can execute which commands. We are going to grant ourselves access to sudo by adding:

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

The specified user name can now use all root permissions. You can also allow a user or group of users to have sudo access to only specific services or servers instead of the ALL parameter, but that's another topic.

Several options

Like any good command, there are several great options for sudo to handle more transactions.

Sudo-b runs the command in the background. This is useful for commands that display a lot of real-time output.

Sudo-s will run the shell specified to elevate permissions, providing you with a # prompt (don't forget to exit! )

Sudo su-will make you the root user and load your custom user environment variables.

Thank you for reading this article carefully. I hope the article "how to use sudo commands in Linux system" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report