Encryption / decryption of the password stored in the configuration file

I have a simple Bash script automating tasks that require password based authentication. I currently store credentials in plain text:

$ cat ~/.myconfig
username=foo
password=bar

Obviously this is bad - so I am wondering if there is a simple way to encrypt / decrypt a password using a public / private key pair. Using another password for encryption will not bring much, so I want this to happen almost automatically.

I did some research (here and elsewhere), but I went out of my depth on this ...

+5
source share
3 answers

You can save the password in the amount of md5, add salt to.

create

\#!/bin/bash

salt=12345_

protocol=sha1sum

read -p "Enter login: " username
read -p -s "Password: " pass1
read -p -s "Repeat: pass2

if [ "pass1 != pass2" ]; then echo "Pass missmatch"; exit 1; else password=pass1; fi

echo -en "$username " >> ./mypasswd
echo -e "${salt}${password} | $protocol | awk '{print $1}'" >> ./mypqsswd

:

\#!/bin/bash
salt=12345_ #(samesalt)
protocol=sha1sum

read -p "Enter username: " username
read -p -s "Enter password: " password

if [ `grep $username ./mypasswd | awk '{print $2}' != `echo -e "`echo ${salt}${password} | $protocol | awk '{print $2}'`" ]; then echo -e "wrong username or password"; exit 127; else echo -e "login successfull"; fi

.

+3

; , / , .
- - , ssh-agent, .

(: )

+3

If you just want to hide the password, save its SHA1 hash. Compare the hash of the entered password with the stored hash.

+2
source

All Articles