加密脚本文件后出现 Unix shell 错误
Unix shell error after encrypting a script file
我有 2 个 shell 脚本 - 一个调用另一个脚本。
callouter.sh, callscript.sh.
callouter.sh :
export oraSchemaPass='scott/tiger'
echo 'This script is about to run another script'
sh ./callscript.sh
callscript.sh :
sqlplus -S ${oraSchemaPass} @/home/scripts/callscript.sql
callscript.sql 是:
set pagesize 1000
select * from emp;
EXIT
这很好用。没有任何错误。顺便说一下,这是 korn shell。
现在我做了两件事:
使用 openssl 加密了 callouter.sh :
openssl enc -e -aes-256-cbc -salt -a -in /home/scripts/callouter.sh -out /home/scripts/callouter.enc -pass pass:W3lc0m3987
文件加密成功
将 callouter.sh 内容替换为:
eval $( /home/scripts/decrypt.sh /home/scripts/callouter.enc )
decrypt.sh 的内容是:
openssl enc -d -e -aes-256-cbc -a -in -pass pass:W3lc0m3987
现在当我 运行 callouter.sh 我得到以下错误:
./callouter.sh: Line 1: export: `This script is about to run another script': not a valid identifier
./callouter.sh: Line 1: export: `./callscript.sh': not a valid identifier
谁能帮我解决这个错误?我在网上搜索了这个错误,它与无效变量和不正确使用倒引号有关。我仔细检查了我的脚本,没有发现这样的错误。我开始认为是加密文件导致的。
编辑:目的是隐藏 Oracle 模式的密码。是的,出于问题的目的,我使用了 decrypt.sh。在环境 decrypt.sh 中,只有调用脚本的用户才能访问。为此,我们设置了一个环境变量 SEC_DIR,它将成为每个用户的主目录。因此,例如用户 'A' 将 SEC_DIR 作为 /home/A/dev/sec_dir。在这个 decrypt.sh 里面将放置
一般来说,我不推荐您使用第二个密码加密隐藏密码的方法。这并没有增加任何真正的保护,只是需要更多的工作来获取密码。
无论如何,只要能同时读取加密数据和脚本decrypt.sh
嵌入解密密码的人,就可以获得明文数据。
无论如何,这是一个可能的解决方案:
1. 我建议不要加密带有嵌入式登录数据的脚本,而是加密只包含登录数据作为文本的文件。
示例:
login.txt
scott/tiger
用同样的方式加密:
openssl enc -e -aes-256-cbc -salt -a -in login.txt -out login.enc -pass pass:W3lc0m3987
在脚本中使用解密 callscript.sh
,例如
sqlplus -S "$( /home/scripts/decrypt.sh login.enc )" @/home/scripts/callscript.sql
2. 基于您的方法的另一种选择可能是
/home/scripts/decrypt.sh /home/scripts/callouter.enc | /bin/bash
(将 /bin/bash
替换为您要使用的 shell。)
错误 export: `something': not a valid identifier
是由于使用 $( ... )
不带引号造成的。示例:
$ printf "a\nb\nc\n"
a
b
c
$ echo x$(printf "a\nb\nc\n")y
xa b cy
$ echo x"$(printf "a\nb\nc\n")"y
xa
b
cy
3. 这意味着你也可以使用
eval "$( /home/scripts/decrypt.sh /home/scripts/callouter.enc )"
在 3 个建议的解决方案中,我推荐解决方案 1 作为最不邪恶的。解决方案 1 将命令的输出作为参数传递给 sqlplus
,而 2 和 3 通过 shell 执行命令的输出,这是更高的安全风险。
我有 2 个 shell 脚本 - 一个调用另一个脚本。 callouter.sh, callscript.sh.
callouter.sh :
export oraSchemaPass='scott/tiger'
echo 'This script is about to run another script'
sh ./callscript.sh
callscript.sh :
sqlplus -S ${oraSchemaPass} @/home/scripts/callscript.sql
callscript.sql 是:
set pagesize 1000
select * from emp;
EXIT
这很好用。没有任何错误。顺便说一下,这是 korn shell。
现在我做了两件事:
使用 openssl 加密了 callouter.sh :
openssl enc -e -aes-256-cbc -salt -a -in /home/scripts/callouter.sh -out /home/scripts/callouter.enc -pass pass:W3lc0m3987
文件加密成功
将 callouter.sh 内容替换为:
eval $( /home/scripts/decrypt.sh /home/scripts/callouter.enc )
decrypt.sh 的内容是:
openssl enc -d -e -aes-256-cbc -a -in -pass pass:W3lc0m3987
现在当我 运行 callouter.sh 我得到以下错误:
./callouter.sh: Line 1: export: `This script is about to run another script': not a valid identifier
./callouter.sh: Line 1: export: `./callscript.sh': not a valid identifier
谁能帮我解决这个错误?我在网上搜索了这个错误,它与无效变量和不正确使用倒引号有关。我仔细检查了我的脚本,没有发现这样的错误。我开始认为是加密文件导致的。
编辑:目的是隐藏 Oracle 模式的密码。是的,出于问题的目的,我使用了 decrypt.sh。在环境 decrypt.sh 中,只有调用脚本的用户才能访问。为此,我们设置了一个环境变量 SEC_DIR,它将成为每个用户的主目录。因此,例如用户 'A' 将 SEC_DIR 作为 /home/A/dev/sec_dir。在这个 decrypt.sh 里面将放置
一般来说,我不推荐您使用第二个密码加密隐藏密码的方法。这并没有增加任何真正的保护,只是需要更多的工作来获取密码。
无论如何,只要能同时读取加密数据和脚本decrypt.sh
嵌入解密密码的人,就可以获得明文数据。
无论如何,这是一个可能的解决方案:
1. 我建议不要加密带有嵌入式登录数据的脚本,而是加密只包含登录数据作为文本的文件。
示例:
login.txt
scott/tiger
用同样的方式加密:
openssl enc -e -aes-256-cbc -salt -a -in login.txt -out login.enc -pass pass:W3lc0m3987
在脚本中使用解密 callscript.sh
,例如
sqlplus -S "$( /home/scripts/decrypt.sh login.enc )" @/home/scripts/callscript.sql
2. 基于您的方法的另一种选择可能是
/home/scripts/decrypt.sh /home/scripts/callouter.enc | /bin/bash
(将 /bin/bash
替换为您要使用的 shell。)
错误 export: `something': not a valid identifier
是由于使用 $( ... )
不带引号造成的。示例:
$ printf "a\nb\nc\n"
a
b
c
$ echo x$(printf "a\nb\nc\n")y
xa b cy
$ echo x"$(printf "a\nb\nc\n")"y
xa
b
cy
3. 这意味着你也可以使用
eval "$( /home/scripts/decrypt.sh /home/scripts/callouter.enc )"
在 3 个建议的解决方案中,我推荐解决方案 1 作为最不邪恶的。解决方案 1 将命令的输出作为参数传递给 sqlplus
,而 2 和 3 通过 shell 执行命令的输出,这是更高的安全风险。