The sudo command allows a trusted user to run a program as another user, which by default is the root user. If you spend a lot of time on the command line, sudo is one of the commands you use all the time. Normally, to grant sudo access, you add the user to the sudo group defined in the sudoers file. On Debian, Ubuntu and their derivatives, members of the sudo group are given sudo privileges. On RedHat based distributions like CentOS and Fedora, the name of the sudo group is wheel. Each member of the group will be prompted for their password before running the sudo command. This adds an extra layer of security and is the preferred way to grant sudo privileges to users. As shown below: However, in some cases, such as running automated scripts, you may want to configure the sudoers file and allow certain users to run sudo commands without asking for a password. Add User to Sudoers File The sudoers file contains information that determines sudo permissions for users and groups. You can configure user sudo access by modifying the sudoers file or adding configuration files to the Before making any changes, it is a good idea to back up your current files: The date command will append the current date to the backup file name. Use the visudo command to open the /etc/sudoers file: When making changes to the sudoers file always use visudo this command checks after editing and if there are syntax errors the changes will not be saved. If you open the file with a text editor, syntax errors will result in losing sudo access. On most systems, the visudo command opens the /etc/sudoers file using the vim text editor. If you don't have experience with vim, you can use another text editor. For example, to change the editor to GNU nano, you would run: Scroll down to the end of the file and add the following line, which allows the user "linuxidc" to run any command with sudo without asking for a password at the beginning: As shown below: Don’t forget to change “linuxidc” with the username you want to grant access to. If you want to allow the user to run only specific commands without entering a password, specify the command after the NOPASSWD keyword. For example, to allow only the mkdir and mv commands: In /etc/sudoers file When you are finished, save the file and exit the editor. Using Instead of editing the sudoers file, you can add new files to the /etc/sudoers.d directory with authorization rules. This approach will make management of sudo permissions more maintainable. Open a text editor and create the file: You can name the file whatever you want, but it's usually best to use your username as the filename. Add the same rules you added to the sudoers file: Finally, save the file and close the editor. Summarize Running sudo without a password is useful when you have scripts that a non-root user needs to perform administrative tasks. The above is the method that I introduced to you to run sudo command in Linux without entering a password. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Sharing the detailed process of setting up Mysql5.6 to allow external network access
>>: An example of installing MySQL on Linux and configuring external network access
This article takes Centos7.6 system and Oracle11g...
Background Threads •Master Thread The core backgr...
Table of contents 1 What is SSH 2 Configure SSH p...
Table of contents Preface Introduction Live Easy ...
Regular expressions are often used to search and ...
First install ssh in Linux, taking centos as an e...
Since its launch in 2009, flex has been supported...
Table of contents 1. Bootstrap5 breakpoints 1.1 M...
Today's web designs tend to display very larg...
First, let’s take an example: There is a type fie...
Overview Volume is the abstraction and virtualiza...
1. Use absolute positioning and margin The princi...
Table of contents Preface optimization SSR Import...
Sometimes we need to remotely run programs on the...
background All company websites need to support t...