如何运行脚本,如无密码其他用户 [英] how to run script as another user without password

查看:195
本文介绍了如何运行脚本,如无密码其他用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须运行为user2的script.sh。然而,这个脚本只能在user1的在我的应用程序运行。

I have script.sh that must be run as user2. However, this script can only be run under user1 in my application.

我想下面的命令来运行:

I would like the following command to run:

su user2 -C script.sh

但能够不使用密码运行。

but be able to run without password.

我也希望这是非常严格的,如USER1只能在user2的,没有别的。运行script.sh

I also want this to be very restrictive, as in user1 can only run script.sh under user2 and nothing else.

我试着sudoers文件这样做的,只是尝试小时后得到了不断地混淆。

I've tried doing this with sudoers file and just got endlessly confused after hours of trying.

如果有人可以提供这可怎么完成(而不是一般的东西像使用sudoers的)一个明确的例子,这将是极大的AP preciated。

If somebody can provide an explicit example of how this can be accomplished (instead of something generic like use sudoers), it would be greatly appreciated.

推荐答案

呼叫 visudo命令及补充一点:

user1 ALL=(user2) NOPASSWD: /home/user2/bin/test.sh

命令路径必须是绝对!然后从 USER1 外壳调用须藤-u用户2 /home/user2/bin/test.sh 。完成。

The command paths must be absolute! Then call sudo -u user2 /home/user2/bin/test.sh from a user1 shell. Done.

这篇关于如何运行脚本,如无密码其他用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆