gpt4 book ai didi

shell - 存储 shell 脚本密码的最佳方法是什么?

转载 作者:行者123 更新时间:2023-12-04 19:00:28 25 4
gpt4 key购买 nike

我在 Ubuntu 16.04 中有 shell 脚本(example.sh),我将每天使用 cronjob 执行以备份数据库并使用密码将其存档在 7z arhive 中。
所以我需要以某种方式将密码传递给这个脚本。

例子:

#!/bin/sh

mysql_user="root"
mysql_pass="example"
zip_pass="example2"

#there goes logic for backup
...

问题
  • 据我所知,仅将密码存储在 shell 脚本中是不正确且不安全的。
  • 我试图将它作为参数传递给 shell 脚本,例如 sh example.sh myStrongMySQLPassword 7zPassword ,但所有用户都可以使用命令 ps -ef 看到在终端。

  • 那么,使用密码运行 shell 脚本的最安全和最佳选择是什么?

    最佳答案

    您可以使用单独的 config文件并在其中存储凭据。在您的 shell 脚本中读取此配置文件以获取凭据。
    unix stack exchange 上有一些关于如何做到这一点的非常好的文章.有关详细信息,请参阅它:

    hiding-password-in-shell-scripts

    关于shell - 存储 shell 脚本密码的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53098959/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com