Sunday, June 18, 2006

Oracle sqlplus Hide Password

There are several ways to keep the Oracle account password off of the unix command line and away from prying eyes. Connecting as sysdba or using an operating system authenticated account avoids a password altogether.
If you would prefer to hard code a password, this method may be used. It can easily be placed in a script.

$ORACLE_HOME/bin/sqlplus /nolog << EOF
conn username/password@SID

select sysdate
from dual
/
EOF


Some operating systems have the "w" command.
$ w
8:55pm up 9 days, 15:59, 5 users, load average: 0.02, 0.04, 0.89
User tty login@ idle JCPU PCPU what
user1 pts/0 6:58pm 1:57 -ksh
oracle pts/2 1:37pm 25 -ksh
user2 pts/5 7:06pm 54 19 19 sqlplus -s username/pass@THESID


Using "ps" to view the process list, notice how user1 does not expose the password.
$ ps -ef|grep sqlplus
user2 24595 24458 4 19:15:32 pts/5 0:20 sqlplus -s username/pass@THESID
oracle 2758 25017 0 20:55:17 pts/3 0:00 grep sqlplus
user1 28815 28641 0 20:00:02 ? 0:00 sqlplus -s /nolog

No comments:

Post a Comment