Encrypt passwords in shell script
10 August 2023 at 13:31
For example to encrypt the password for
mysql_secure_installation using shell script
install these packages
$ sudo apt install sshpass gnupg2
create a file
$ touch .secrets
$ cat > .secrets
passcode123
^D
Encrypting Your Password
$ gpg -c .secrets
it will create a file with .secrets.gpg
to decrypt
$ gpg -dq .secrets.gpg
create the mariadb secure installation script
$ cat mariadb.sh
#!/bin/bash
save and exit
apt install mariadb-server mariadb-client -y
systemctl enable mariadb.service
mysql_secure_installation <<EOF
y
n
y
gpg -dq secrets.gpg | sshpass
gpg -dq secrets.gpg | sshpass
y
y
y
y
EOF
:wq!
$ sudo chmod +x mariadb.sh
$ sh mariadb.sh