使用Bash Shell脚本加密文件

13

我想使用openssl加密一个文件。我可以通过使用

openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss 

当我运行这个命令时,它会让我输入密码两次。我想用脚本设置密码,并使用了

openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss -pass pritom 

但是它给我以下错误:

Invalid password argument "pritom"
Error getting password 

现在我该怎么办?

2个回答

12

试试这样做 -

openssl des3 -salt -in /pritom/uaeyha_com.sql -out /pritom/a.ss -pass pass:pritom

来自man页面:

密码传递参数
几个命令接受密码参数,通常使用 -passin 和 -passout 分别用于输入和输出密码。这些选项允许从多种来源获取密码。这两个选项都接受一个格式如下的单个参数。如果没有提供密码参数,并且需要密码,则提示用户输入密码:通常从关闭回显的当前终端读取。

   pass:password
             the actual password is password. Since the password is visible to utilities (like 'ps' under Unix)
             this form should only be used where security is not important.

   env:var   obtain the password from the environment variable var. Since the environment of other processes is
             visible on certain platforms (e.g. ps under certain Unix OSes) this option should be used with
             caution.

   file:pathname
             the first line of pathname is the password. If the same pathname argument is supplied to -passin and
             -passout arguments then the first line will be used for the input password and the next line for the
             output password. pathname need not refer to a regular file: it could for example refer to a device
             or named pipe.

   fd:number read the password from the file descriptor number. This can be used to send the data via a pipe for
             example.

   stdin     read the password from standard input.

1
不客气。请注意,如果您在命令行中传递密码,则每个人都可以通过ps -ef看到它。因此最好使用-pass file:pathname从文件中传递密码。祝你好运 :) - jaypal singh
我会在我的.sh文件中使用这段代码,这样就不会有压力了。谢谢。 - Pritom

2

要隐藏它不被ps命令发现,可以使用:

temp_varX=pritom ;
openssl .....  -pass fd:0 <<< "$temp_var"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接