我如何“sudo -i”具体命令

我需要像没有密码的sudo -i一样运行important_script.sh.

如果我有sudoers:

apache ALL = (root) nopASSWD:    /blah/important_script.sh

并运行“sudo /blah/important_script.sh”我可以在没有密码的情况下运行它.

但是,如果我运行“sudo -i /blah/important_script.sh”,我需要输入apache的密码.

如果我将sudoers中的行更改为:

apache ALL = (root) nopASSWD:ALL

我可以在没有密码的情况下运行命令“sudo -i /blah/important_script.sh”.

但我希望能够只运行/blah/important_script.sh,而不是所有命令.

所以,我如何设置只有/blah/important_script.sh可以使用sudo -i运行而无需密码.

解决方法

当我尝试这个时,我收到一条错误消息,提供了问题的线索
Sorry,user bob is not allowed to execute '/bin/bash -c /blah/important_script.sh' as root on host.

请注意,我们被拒绝访问命令/ bin / bash -c …这与我们在sudoers文件/ blah / important_script中指定的命令不同….当你告诉sudo允许用户运行时一个特定的命令,他们必须使用sudoers中指定的确切命令行,所以我们需要适当地更改sudoers.

bob   ALL=(root) nopASSWD: /bin/bash -c /blah/important_script.sh

这现在适用于鲍勃

$sudo -i /bin/bash -c /blah/important_script.sh

那为什么要这样呢?那么sudo的手册页有答案

‑i [command]
The ‑i (simulate initial login) option runs the shell specified by the password database entry of the target user as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified,it is passed to the shell for execution via the shell’s ‑c option. If no command is specified,an interactive shell is executed…

相关文章

1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...
如何抑制stable_secret读取关键的“net.ipv6.conf.all.stabl...
1 删除0字节文件 find -type f -size 0 -exec rm -rf {} ...
## 步骤 1:安装必要的软件包 首先,需要确保系统已安装 `dh...