我有一个小Bash脚本,我用它来访问twitter,并在某些情况下弹出咆哮通知。用脚本存储密码的最佳方法是什么?
I would like to commit this script to the git repo and make it available on GitHub, but I'm wondering what the best way to keep my login/password private while doing this is. Currently, the password is stored in the script itself. I can't remove it right before I push because all the old commits will contain the password. Developing without a password isn't an option. I imagine that I should be storing the password in an external config file, but I thought I'd check to see if there was an established way to handle this before I tried and put something together.
一种方法是使用环境变量设置密码(或API密钥)。
所以这个密码不受修改控制。
使用Bash,您可以使用来设置环境变量
export your_env_variable='your_password'
这种方法可以与Travis这样的持续集成服务一起使用,你存储在GitHub存储库中的代码(没有密码)可以由Travis执行(使用环境变量设置你的密码)。
使用Bash,你可以使用以下命令获取环境变量的值:
echo "$your_env_variable"
使用Python,你可以使用以下命令获取环境变量的值:
import os
print(os.environ['your_env_variable'])
PS:请注意这可能有点风险(但这是一种相当常见的做法)https://www.bleepingcomputer.com/news/security/javascript-packages-caught-stealing-environment-variables/
PS2:这篇题为“如何安全地存储API密钥”的dev.to文章可能会很有趣。
一种方法是使用环境变量设置密码(或API密钥)。
所以这个密码不受修改控制。
使用Bash,您可以使用来设置环境变量
export your_env_variable='your_password'
这种方法可以与Travis这样的持续集成服务一起使用,你存储在GitHub存储库中的代码(没有密码)可以由Travis执行(使用环境变量设置你的密码)。
使用Bash,你可以使用以下命令获取环境变量的值:
echo "$your_env_variable"
使用Python,你可以使用以下命令获取环境变量的值:
import os
print(os.environ['your_env_variable'])
PS:请注意这可能有点风险(但这是一种相当常见的做法)https://www.bleepingcomputer.com/news/security/javascript-packages-caught-stealing-environment-variables/
PS2:这篇题为“如何安全地存储API密钥”的dev.to文章可能会很有趣。