写入要求密码的stdin

时间:2014-04-12 11:06:49

标签: linux bash ubuntu-12.04 openldap

我正在使用bash脚本来配置openldap并为用户和组添加ldif脚本。

如何从bash脚本中编写密码?

这是我在要求输入密码时运行的脚本:

ldapadd -h localhost -D "cn=admin,dc=sysadmin1,dc=hioa,dc=no" -W -x -f /etc/ldap/base.ldif

编辑:

我尝试了这个并使用密码

创建了一个passwd.txt文件
ldapadd -h localhost -D "cn=admin,dc=sysadmin1,dc=hioa,dc=no" -W -x -y'passwd.txt' -f /etc/ldap/base.ldif

但是得到了这个错误:

Warning: Password file passwd.txt is publicly readable/writeable
ldap_bind: Invalid credentials (49)

enter image description here

2 个答案:

答案 0 :(得分:1)

man ldapadd。

-W
Prompt for simple authentication. This is used instead of specifying the password on the command line.

-w passwd
Use passwd as the password for simple authentication.
-y passwdfile
Use complete contents of passwdfile as the password for simple authentication.

所以您似乎正在寻找-w-y的选项,而不是-W

答案 1 :(得分:0)

有两种可能性:

  1. ldapadd从标准输入中读取密码。
  2. ldapadd直接从当前TTY读取密码。
  3. 在第一种情况下,使用类似echo 'MySecretPassword' | ldapadd -h localhost -D "cn=admin,dc=sysadmin1,dc=hioa,dc=no" -W -x -f /etc/ldap/base.ldif的内容就足够了。第二个更复杂,因为你需要一个像expect这样的工具。检查简单重定向是否有效。

相关问题