开发者

Encrypt Mysql password on shell script

开发者 https://www.devze.com 2023-03-11 11:35 出处:网络
How to write the password to result_p.txt in encrypted form and how retrieve it back as well? echo \"Please enter the mysql root password : \"

How to write the password to result_p.txt in encrypted form and how retrieve it back as well?

echo "Please enter the mysql root password : "
stty -echo
read PASSWORD
echo $PASSWORD > result_p.txt
stty echo
if [[ "$PASSWORD"开发者_如何学Python = "amma" ]]
then
echo "Entered Mysql password is :" $PASSWORD 
fi


You could use a small Python script to obfuscate it using Base64:

#!/usr/bin/env python
import getpass
password = getpass.getpass()
open("result_p.txt", "w").write(password.encode("base64"))

Then to read the password:

password = open("result_p.txt").read().decode("base64")


I'm afraid that it has no sense while user can view contents of your shell script. IMHO, the most simple way would be 'chmodding' resultant *result_p.txt* so that it is not readable by regular user.

0

精彩评论

暂无评论...
验证码 换一张
取 消