如何在脚本中隐藏/伪装密码

我使用以下脚本来更改打开目录(Apple的LDAP)密码。

我不喜欢在脚本中留下实际的密码 – 是否有任何方法来隐藏或伪装,以便脚本可以被其他用户使用,但以某种方式看不到密码?

#!/bin/bash PATH=/bin:/usr/bin:/sbin:/usr/sbin export PATH echo echo Enter username you\'d like to change password for: read USERNAME echo echo Enter New Password for "$USERNAME" read PASSWORD dscl -u diradmin -P 'secretpasswordhere' /LDAPv3/127.0.0.1 passwd /Users/$USERNAME $PASSWORD echo Password successfully changed for $USERNAME to $PASSWORD 

您可以让脚本以Set-GID运行,然后从受保护的文件中获取密码信息。 当然这个小组的访问和成员资格应该是有限的。 这是一个非常简单的答案。

另一个想法是让用户input脚本中包含的密码的解密码。 因此只有授权用户(具有解密码的用户)才能运行该脚本。

看看shc

http://www.thegeekstuff.com/2012/05/encrypt-bash-shell-script/

  The whole logic behind the shc is to convert the random.sh shell script to random.sh.xc C program (and of course compile that to generate the random.sh.x executable) 
  • random.sh是原始的未encryption的shell脚本
  • random.sh.x是二进制格式的encryptionshell脚本
  • random.sh.xc是random.sh文件的C源代码。 编译这个C源代码来创build上面encryption的random.sh.x文件。