加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-13 17:21:27 所属栏目:Linux 来源:网络整理
导读:我需要像没有密码的sudo -i一样运行important_script.sh. 如果我有sudoers: apache ALL = (root) NOPASSWD: /blah/important_script.sh 并运行“sudo /blah/important_script.sh”我可以在没有密码的情况下运行它. 但是,如果我运行“sudo -i /blah/importan
我需要像没有密码的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…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读