Friday, September 6, 2013

How to Encrypt Password in SQLPLUS


As you know, sometimes it’s needed to do some oracle operations via UNIX script pre/post Informatica load operations. At the same time, security is important too. If you just do ‘sqlplus user/password@database’, it’s a major security flaw. Anyone can see password in script. Also run ‘ps’ command on UNIX linux and find out database credentials.
In order to make sure password is encrypted, below is the right way to do this:
Step 1: Create hidden encrypted password file  (assuming password is ‘fx=120’)
echo fx=120 | crypt `hostname` > .encry.connect
Step 2: Use in script as below (sample script)
export ORACLE_SID=DATABASE NAME
export ORACLE_USER=USER
export ORACLE_PW=$(crypt `hostname` < encry.connect)
sqlplus -S /nolog <<-SQLCMDS
connect ${ORACLE_USER}/${ORACLE_PW}@${ORACLE_SID}
select * from dual ; <-- Give commands here
exit
SQLCMDS

3 comments: