Home  >  Article  >  System Tutorial  >  How to run sudo command without entering password in Linux

How to run sudo command without entering password in Linux

PHPz
PHPzforward
2024-02-12 22:33:121129browse

Assuming you are running a Linux system on a computer that you only use, such as a laptop, you will need to enter a password every time you call sudo, which will be tedious in the long run. Therefore, in this guide, we will describe how to configure the sudo command to run without entering a password.

如何在 Linux 中不输入密码运行 sudo 命令

This setting is done in the /etc/sudoers file, which is the default security policy using the sudo command; in the user permissions specification section.

Important: In the sudeors file, the authenticate parameter that is turned on by default is used for verification purposes. If it is set, the user must authenticate with a password (or other authentication method) before they can run commands with sudo.

However, this default can be overridden using the NOPASSWD (no password required when user calls "sudo" command) flag.

The syntax for configuring user permissions is as follows:

  1. user_list host_list=effective_user_list tag_list command_list
    

in:

  1. user_list – User list or user aliases that have been set.
  2. host_list – A list of hosts or host aliases on which the user can run sudo.
  3. effective_user_list – List of users running as this user or alias
  4. tag_list – tag list, such as NOPASSWD.
  5. command_list – A list of commands or command aliases that the user can run using sudo.

To allow a user (aaronkilik in the example below) to run all commands using sudo without entering a password, open the sudoers file:

  1. $ sudo visudo
    

Add the following lines:

  1. aaronkilik ALL=(ALL) NOPASSWD: ALL
    

For groups, use the % character before the group name; this means that all members of the sys group can use sudo without a password.

  1. %sys ALL=(ALL) NOPASSWD: ALL
    

To allow users to run specified commands (/bin/kill) using sudo without a password, add the following lines:

  1. aaronkilik ALL=(ALL) NOPASSWD: /bin/kill
    

The following lines will allow members of the sys group to use sudo to run commands: /bin/kill, /bin/rm without entering a password:

  1. %sys ALL=(ALL) NOPASSWD: /bin/kill, /bin/rm
    

The above is the detailed content of How to run sudo command without entering password in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete