Hello Techie's
If someone reading your shell script and you have provided password variable without encyption, then the person reading that script can use password credentials for his own sake. In order overcome this, we need to encrypt the passwords so that person reading the script will not understand the password credentials.
------------------------------------------
Example s3 Bucket credentials:
Bucket_name: Archived
s3_access_key: abcdef
s3_secret_key: ghijkl
-- > Follow below steps to encrypt your bucket credentials.
---------------------------------------------
Step 1: we have create our common key to encrypt access_key & secret_key of s3 bucket.
---------------------------------------------
key: techie
---------------------------------------------
Step 2: use below command to find base64 encryted format of your comman key and s3 bucket credentials.
echo "techie" | base64
key=$(echo "dGVjaGllCg==" | base64 -d)
echo "ghijkl" | openssl enc -aes-256-cbc -md sha512 -a -salt -pass pass:${key}
U2FsdGVkX1/JqHKlUL5HM1d2gH9L0S4ScDux9uaNkh0=
Step 3: Assigning above encrypted credentials to variable
encrypted_s3_access_key=U2FsdGVkX198KxzvnjkkgROpWbZ2m/+vMZ35QQ5F6c8=
encrypted_s3_secret_key=U2FsdGVkX1/JqHKlUL5HM1d2gH9L0S4ScDux9uaNkh0=
Step 4: Store the decrypted s3 bucket credential in variable so that we can use this credentials to login the bucket
s3_access_key=$(echo ${encrypted_s3_access_key}| openssl enc -aes-256-cbc -md sha512 -a -d -salt -pass pass:${key})
s3_secret_key=$(echo ${encrypted_s3_secret_key}| openssl enc -aes-256-cbc -md sha512 -a -d -salt -pass pass:${key})
Step 5: Check if credentials variables are decryted and assigned to variable
#------------------------------------------------------------------------------------
#your script should look like below#------------------------------------------------------------------------------------
key=$(echo "dGVjaGllCg==" | base64 -d)
encrypted_s3_access_key=U2FsdGVkX198KxzvnjkkgROpWbZ2m/+vMZ35QQ5F6c8=
encrypted_s3_secret_key=U2FsdGVkX1/JqHKlUL5HM1d2gH9L0S4ScDux9uaNkh0=
s3_access_key=$(echo ${encrypted_s3_access_key}| openssl enc -aes-256-cbc -md sha512 -a -d -salt -pass pass:${key})
s3_secret_key=$(echo ${encrypted_s3_secret_key}| openssl enc -aes-256-cbc -md sha512 -a -d -salt -pass pass:${key})
------------------------------------------------------------------------------------------
Comments
Post a Comment