Home > other >  Cannot read encrypted password in shell script
Cannot read encrypted password in shell script

Time:12-04

I'm trying to connect to a Tableau Server using an encrypted password. The usual command to connect is:

tabcmd login -u user -p password

I have encrypted a password and stored it into a text file with the following script.

echo "strongpw" | openssl enc -aes-256-cbc -md sha512 -a -pbkdf2 -iter 100000 \
-salt -pass pass:Secret@123# > secret.txt
  • strongpw being the string I want to encrypt
  • Secret@123# being the password that is used during the encryption

Once that done, I have a secret.txt file with something like this:

U2FsdGVkX1/VyNZZ/RTaymM4F5DHNNG0iYapp3u3 WI=

I can then use the following script to decrypt my password:

cat secret.txt | openssl enc -aes-256-cbc -md sha512 -a -d -pbkdf2 -iter 100000 \
 -salt -pass pass:Secret@123#

output: strongpw

Finally, I created an .sh script the user might execute to connect to the server. The script is supposed to decrypt the password and store it in the variable.

#bin/bash

USERNAME=test
PASSWD=`cat secret.txt | openssl enc -aes-256-cbc -md sha512 -a -d -pbkdf2 \ 
-iter 100000 -salt -pass pass:Secret@123#`

tabcmd login -u $USERNAME -p $PASSWD

I then made my script executable with chmod x

Unfortunately, when trying to running, I'm always encountering either invalid argument or extra arguments given as errors.

Any suggestion on how to fix this?

Thank you!

CodePudding user response:

maybe you can try with the '-in' tag to provide the input file instead of using cat?

CodePudding user response:

Thanks to @MarcoLucidi for showing me shellcheck.net :)

Here's how I had to modify my .sh file to make it work:

#bin/bash

USERNAME=test
var=$(cat secret.txt | openssl enc -aes-256-cbc -md sha512 -a -d -pbkdf2 -iter 100000 \
 -salt -pass pass:Secret@123#)
tabcmd login -u “$USERNAME” -p “$var”
tabcmd runschedule "PMS Daily 6AM"
  • Related