简体   繁体   中英

Write to stdin which asks for password

I am working on a bash script to configure openldap and add ldif script with users and groups.

How can I write the password from the bash script ?

This is the script I run when it asks for password:

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

EDIT:

I tried this and created a passwd.txt file with the password:

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

But gets this error:

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

在此处输入图片说明

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.

So seems you are looking for option of -w or -y , not -W

There're two possibilities:

  1. ldapadd reads the password from the standard input.
  2. ldapadd reads the password directly from the current TTY.

In the first case it's enough to use something like this echo 'MySecretPassword' | ldapadd -h localhost -D "cn=admin,dc=sysadmin1,dc=hioa,dc=no" -W -x -f /etc/ldap/base.ldif echo 'MySecretPassword' | ldapadd -h localhost -D "cn=admin,dc=sysadmin1,dc=hioa,dc=no" -W -x -f /etc/ldap/base.ldif . The second one is more complicated because you need a tool like expect . Check if the simple redirection works first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM