Blog Moved

Thursday, July 23, 2015

Encoding a Passphrase in a Bash Script

There's an ftp server I need to access from time to time, and the password is one that was assigned to me, and so not one that is very memorable. Like 87sa!9s8op12mn or something. One solution is to put the password in a script and use that, but there are some obvious reasons that is a bad idea. A better idea is to adapt the encryption and decryption methods mentioned in this post.

First, we need to get an encrypted version of the old password:
echo  '87sa!9s8op12mn' | openssl enc -des -a -e -pass pass:MyMemorablePassword
That returns:
So now, in our script, we can simply do this:
PASSWORD=$(echo U2FsdGVkX1/ewCk0xYTJF33NCLpJ6eULDqQC60Hh3oY=  | openssl enc -des -a -d);
When that runs, it will ask us for OUR password, which it will then use to decrypt the actual password.

No comments:

Post a Comment

Comments welcome, but they are expected to be civil.
Please don't bother spamming me. I'm only going to delete it.