首页 > 解决方案 > 加密/解密密码并通过 ksh 脚本使用

问题描述

我在具有应用用户(无 root)的 RedHat linux 服务器上工作。我有一个 ksh 脚本,可以sqlplus通过这个命令在不同的数据库上建立一些连接:

sqlplus -s myuser/password@DBNAME.

此连接需要密码,每个密码都与其他密码不同。

我想加密这些密码并将它们存储在一个文件中。然后,每次我运行我的脚本时,它都必须读取一个特定的加密密码,解密它,最后将它传递给sqlplus命令。

关于使用特定的密码,我想我可以在行首插入一个标签,但我的问题是如何使用 openSSL 加密此密码(我无法在机器上安装任何工具),以及它是否是避免普通密码的安全方法文本密码发送。提前致谢。

标签: shellscriptingopensslkshpassword-encryption

解决方案


就像是 :

凭证文件

#!/bin/ksh
#######################################################
#
# Source for UID/Password. MUST be with access 600
#
# .credential.sh
#
# Usage : . .credential.sh
#
######################################################

#Declaring associative array

typeset -A Password

# Setting the values

Password[USER1]="Passwd1"
Password[USER2]="Passwd2"

在你的脚本中:

#!/bin/ksh

#sourcing the credential files
. /foo/bar/.credential.sh

#............... Some code
myuser=USER1 # Or whatever means to set the user variable
#............... Some code

sqlplus -s $myuser/${Password[$myuser]}@DBNAME

#............... Some code

推荐阅读