shell - 加密/解密密码并通过 ksh 脚本使用
问题描述
我在具有应用用户(无 root)的 RedHat linux 服务器上工作。我有一个 ksh 脚本,可以sqlplus
通过这个命令在不同的数据库上建立一些连接:
sqlplus -s myuser/password@DBNAME
.
此连接需要密码,每个密码都与其他密码不同。
我想加密这些密码并将它们存储在一个文件中。然后,每次我运行我的脚本时,它都必须读取一个特定的加密密码,解密它,最后将它传递给sqlplus
命令。
关于使用特定的密码,我想我可以在行首插入一个标签,但我的问题是如何使用 openSSL 加密此密码(我无法在机器上安装任何工具),以及它是否是避免普通密码的安全方法文本密码发送。提前致谢。
解决方案
就像是 :
凭证文件
#!/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
推荐阅读
- android - Android Studio - 关闭浮动 Logcat 窗口的快捷方式?
- java - Jersey 2 / JAX-RS 自定义协议 / 端口
- flutter - Flutter:键盘的选项卡按钮在 TextFormFields 中创建一个空间
- html - 从两侧环绕图像或形状的文本
- r - ggplot - 根据用于绘图的数据框中的变量添加标题
- unit-testing - 无法在颤振测试中加载资产
- c++ - 为什么它不更新我的函数变量?(带类的线程)
- pyspark - Pyspark F.当 X 不在 Y 中时
- azure - Azure 门户上的 SQL Server 防火墙规则 UI 似乎已损坏
- docker - GitHub Docker 操作拉取请求分支