[英]How to make passwordless switch to another user in a shell script
我想从hadoopmaster到hduser。 当我在终端上这样做时,我做:
su - hduser
然后我要求输入密码,然后我输入密码,然后进入hduser。 如何在shell脚本中执行相同操作而不必担心密码? 我尝试了sudoers
文件方法,我把它放在:
root ALL=(ALL:ALL) ALL
hduser ALL=(ALL:ALL) ALL
hadoopmaster ALL=(ALL:ALL) NOPASSWD: /bin/su hduser
(here I tried different combinations of the line with and without the '-' and also
with and without /bin)
我做了这个,当我做su hduser
或su - hduser
,它再次提示我输入密码。 我该怎么办?
你不要在sudoers文件中使用“su”,你需要使用“sudo”。 所以,你需要一个命令行,如:
sudo su - hduser
只要你在sudoers文件中有适当的行,你会想要你想要的。 像这样的一行:
hadoopmaster ALL=(ALL:ALL) NOPASSWD: su - hduser
应该做的伎俩。
我在/ etc / sudoers文件上添加了user = ranjith,
ranjith ALL=(ALL) NOPASSWD: ALL
现在我们可以用,
"sudo, sudoedit - execute a command as another user"
[ranjith@ranjith ~]$ sudo -i
# id
uid=0(root) gid=0(root) groups=0(root)
它为我工作,现在我可以直接从我的本地用户“ranjith”登录到root。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.