python 配置文件中密码不能是明文_避免以明文形式存储密码?

这篇博客探讨了一个Python脚本中避免明文存储密码的问题。通过使用环境变量、加密存储以及第三方库如Keyring来管理敏感信息,作者提出了替代明文存储密码的解决方案。此外,还讨论了如何在cron任务中安全地使用这些方法。
摘要由CSDN通过智能技术生成

import subprocess

import os

import stat

dmi = subprocess.check_output('dmidecode', shell=True)

#print(variable)

#run program once as root then cron it as root

try :

file = open("/var/log/serialcontrol/dmidecode.txt", "r")

file.close()

except FileNotFoundError:

script = '/var/tmp/serialcontrol.bash'

with open(script, 'w') as file:

file.write("#!/bin/bash/\nif [ ! -d /var/log/serialcontrol/ ]\nthen\n\tmkdir /var/log/serialcontrol/\nfi");

#st = os.stat(script)

#os.chmod(script, st.st_mode | stat.S_IEXEC)

subprocess.call(["bash", script])

subprocess.call(["rm", script])

#with open('/var/log/serialcontrol/dmidecode.txt' , 'w') as file:

# file.write(dmi);

file = open("/var/log/serial

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值