使用Visudo启用无密码sudo命令

时间:2013-04-11 08:10:01

标签: passwords sudo sudoers visudo

我的主目录中有一个名为“rescan.sh”的脚本。我创建了一个指向脚本的符号链接并将其放在/ usr / local / bin中。该脚本执行以下操作:

#!/bin/bash
sudo sh -c "echo 1 > /sys/bus/pci/rescan"

我需要这个脚本才能让我的读卡器正常工作,我需要在每次重启后运行这个脚本(长篇故事,不同的问题,不要进入这个)。

我想要实现的是脚本在启动时自动运行。我需要sudo权限来运行脚本,因此我需要一个无密码的sudo用于此脚本。我可以用期望或用visudo做到这一点。出于安全考虑,我只考虑后者。我一直在试验visudo,但还没有任何工作。我希望得到一些帮助来设置它。这是我的视觉:

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    editor=/usr/bin/vim
Defaults    env_reset
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
%admin ALL=(ALL) NOPASSWD:/usr/local/bin/rescan

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

其他信息:

  • 这个系统是我自己的个人笔记本电脑(我是root,sudo等)
  • 运行Linux Mint 13 Cinnamon 64位

1 个答案:

答案 0 :(得分:0)

这个问题很古老,这个答案只是一个猜测但是......

改变

%admin ALL=(ALL) NOPASSWD:/usr/local/bin/rescan

your_usual_user_name ALL=(ALL) NOPASSWD:/usr/local/bin/rescan

可能有所帮助。但是,请注意:我不知道与此相关的安全风险!

相关问题