Oracle的ORAPWD工具用來建立密碼檔案

ljm0211發表於2012-06-20

擁有SYSDBA和SYSOPER許可權的使用者,可以執行類似CREATE DATABASE、DROP DATABASE、RECOVER、STARTUP、SHUTDOWN之類的操作。這兩個許可權不但很高,而且很特殊。因為這些使用者不能透過資料庫進行驗證。當資料庫關閉後,如果一個擁有SYSDBA許可權的使用者要啟動資料庫,那麼這個使用者的驗證肯定要放在資料庫之外。

因此Oracle提高了作業系統驗證和密碼檔案驗證兩種方式。而ORAPWD正是Oracle用來生成密碼檔案的工具。

密碼檔案一般放在ORACLE_HOME/dbs目錄下,對於WINDOWS環境,則是ORACLE_HOMEdatabase目錄。檔名稱為orapw + $ORACLE_SID。

這個命令很簡單:

$ orapwd -h
Usage: orapwd file= password= entries=

where
file - name of password file (mand),
password - password for SYS (mand),
entries - maximum number of distinct DBA and OPERs (opt),
There are no spaces around the equal-to (=) character.

建立密碼檔案可以重新設定SYS使用者的密碼:

$ sqlplus /nolog

SQL*Plus: Release 9.2.0.4.0 - Production on 星期五 4月 10 01:44:03 2009

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> conn sys/abc@bjtest as sysdba
ERROR:
ORA-01017: invalid username/password; logon denied


SQL> conn sys/test@bjtest as sysdba已連線。
SQL> exit從Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production中斷開

可以看到指定bjtest服務名的時候,是沒有使用作業系統驗證的,可以看到目前SYS使用者的密碼是TEST。

下面透過ORAPWD工具新建一個密碼檔案,指定一個新的密碼:

$ cd $ORACLE_HOME/dbs
$ mv orapwbjtest orapwbjtest.bak
$ orapwd file=orapwbjtest password=newpasswd entries=100

其中password用來設定SYS使用者密碼,而entries表示密碼檔案中可以儲存多少條記錄。需要注意,這個值並不是一個確切的數量,真正可以儲存的記錄數可能會有所出入,這和1個作業系統塊能儲存多少條記錄有關係。

下面看看新密碼是否生效:

$ sqlplus /nolog

SQL*Plus: Release 9.2.0.4.0 - Production on 星期五 4月 10 01:45:50 2009

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

SQL> conn sys/test@bjtest as sysdba
ERROR:
ORA-01031: insufficient privileges


SQL> conn sys/newpasswd@bjtest as sysdba
ERROR:
ORA-01031: insufficient privileges


SQL> conn / as sysdba已連線。
SQL> shutdown immediate資料庫已經關閉。已經解除安裝資料庫。
ORACLE例程已經關閉。
SQL> startup
ORACLE例程已經啟動。

Total System Global Area 9432971568 bytes
Fixed Size 756016 bytes
Variable Size 838860800 bytes
Database Buffers 8589934592 bytes
Redo Buffers 3420160 bytes資料庫裝載完畢。資料庫已經開啟。
SQL> conn sys/test@bjtest as sysdba
ERROR:
ORA-01017: invalid username/password; logon denied

警告: 您不再連線到 ORACLE。
SQL> conn sys/newpasswd@bjtest as sysdba已連線。

可以看到將原有的密碼檔案替換後,新的密碼檔案並不會當時生效,從返回的錯誤ORA-1031也可以看出這個問題。

需要Oracle重新啟動,載入新的密碼檔案後才可以生效,這是SYS密碼已經變為新設定的密碼了。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/11411056/viewspace-733448/,如需轉載,請註明出處,否則將追究法律責任。

相關文章