0

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

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

我需要这个脚本来使我的读卡器正常工作,并且每次重新启动后我都需要运行这个脚本(长篇大论,不同的问题,不要讨论这个)。

我想要实现的是脚本在启动时自动运行。我需要 sudo 权限来运行脚本,因此我需要一个无密码的 sudo 来运行这个脚本。我可以用expect或visudo来做到这一点。由于安全原因,我只考虑后者。我一直在尝试使用 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 位
4

1 回答 1

0

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

改变

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

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

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

于 2014-03-06T21:04:49.633 回答