oracle本地驗證和密碼檔案

abin1703發表於2017-05-17
oracle的密碼檔案作用是進行DBA許可權的身份驗證。
當資料庫開啟到mount狀態時,資料庫必須要具備一個很重要的密碼檔案/口令檔案,這個檔案預設是存放在$ORACLE_HOME/dbs下的,預設名稱為orapw<sid>。如果密碼檔案丟失了,那麼資料庫啟動到mount的時候就會出錯。
密碼檔案裡面存放了sysdba/sysoper使用者的使用者名稱和口令:
[oracle@localhost dbs]$ strings orapworcl 
]\[Z
ORACLE Remote Password file
INTERNAL
6A75B1BBE50E66AB
4DE42795E66117AE
IL      H
在資料庫沒有啟動之前,資料庫的內建使用者是無法透過資料庫本身來驗證身份的,透過密碼檔案,
oracle就可以實現對使用者的驗證,在資料庫未啟動之前登入,進而啟動資料庫。
密碼檔案是可以透過orapwd工具重建的,所以在通常的備份策略中可以不必包含密碼檔案。

oracle有兩種認證方式:作業系統認證(要求該使用者屬於本地DBA組,然後透過作業系統認證登入oracle,從而啟動資料庫),密碼檔案認證
oracle使用哪種認證方式決定在於兩個引數:
(1)remote_login_passwordfile=none|exclusive|shared
none:不使用密碼檔案認證。如果選擇了這個值,就相當於遮蔽了密碼檔案的內容了。
exclusive:要密碼檔案認證,自己獨佔使用(預設值)
shared:要密碼檔案認證,不同例項dba使用者可以共享密碼檔案

(2)位於$ORACLE_HOME/network/admin/sqlnet.ora
SQLNET.AUTHENTICATION_SERVICES=none|all|nts
none:關閉作業系統認證,只能密碼認證
all:用於linux/unix平臺,關閉本機密碼檔案認證,採用作業系統認證
nts:用於windows平臺

實驗:
oracle伺服器位於Linux作業系統,客戶端位於windows作業系統。
首先,檢視remote_login_passwordfile引數值:
SYS@orcl 11-SEP-14>show parameter remote_login_passwordfile

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
remote_login_passwordfile            string      EXCLUSIVE

找到$ORACLE_HOME/network/admin目錄下的sqlnet.ora,在檔案末尾加上:
SQLNET.AUTHENTICATION_SERVICES=NONE
#Purpose: Use parameter SDP.PF_INET_SDP to specify the protocol family or
#         address family constant for the SDP protocol on your system.
#
#Supported since:  11.0
#
SQLNET.AUTHENTICATION_SERVICES=none

即使用密碼檔案認證方式,那麼如果我們在本地使用sqlplus "/as sysdba"就會提示錯誤資訊:
[oracle@localhost ~]$ sqlplus "/as sysdba"
SQL*Plus: Release 11.2.0.1.0 Production on Fri Sep 12 22:45:56 2014

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

ERROR:
ORA-01031: insufficient privileges
此時我們必須使用sys使用者名稱和密碼才可以登入:
[oracle@localhost ~]$ sqlplus "sys/sys as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Fri Sep 12 22:47:08 2014

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

進入sqlnet.ora把SQLNET.AUTHENTICATION_SERVICES=none改成“=all”,存檔退出。
再次使用sqlplus "/as sysdba"登入的時候使用的就是本地認證:
[oracle@localhost ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 11.2.0.1.0 Production on Fri Sep 12 22:49:51 2014

Copyright (c) 1982, 2009, Oracle.  All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

另外,我們可以使用orapwd這個工具來生成密碼檔案。
首先看看orapwd的用法:
[oracle@localhost ~]$ orapwd
Usage: orapwd file=<fname> entries=<users> force=<y/n> ignorecase=<y/n> nosysdba=<y/n>


  where
    file - name of password file (required),
    password - password for SYS will be prompted if not specified at command line,
    entries - maximum number of distinct DBA (optional),
    force - whether to overwrite existing file (optional),
    ignorecase - passwords are case-insensitive (optional),
    nosysdba - whether to shut out the SYSDBA logon (optional Database Vault only).
    
  There must be no spaces around the equal-to (=) character.

我們把位於$ORACLE_HOME/dbs目錄下的原orapworcl移到其它目錄。注意,remote_login_passwordfile=exclusive,且sqlnet.ora中SQLNET.AUTHENTICATION_SERVICES=none
在windows上的客戶端嘗試遠端oracle:
SQL> conn sys/sys@win as sysdba
ERROR:
ORA-01031: insufficient privileges

現在我們使用orapwd來重建密碼檔案:
[oracle@localhost dbs]$ orapwd file=$ORACLE_HOME/dbs/orapworcl password=sys entries=5
[oracle@localhost dbs]$ ls
hc_DBUA0.dat  initorcl      lkORCL         peshm_DUMMY_0  spfileorcl.ora
hc_orcl.dat   initorcl.ora  orapworcl      peshm_orcl_0
init.ora      lkDUMMY       peshm_DBUA0_0  snapcf_orcl.f

再次嘗試遠端連線oracle:
SQL> conn sys/sys@win as sysdba
已連線。

看看這個密碼檔案的內容:
[oracle@localhost dbs]$ strings orapworcl
]\[Z
ORACLE Remote Password file
INTERNAL
6A75B1BBE50E66AB
4DE42795E66117AE

在資料庫中建立一個新的使用者並授予sysdba的許可權:
SYS@orcl 11-SEP-14>create user sunny identified by sunny;

User created.
SYS@orcl 11-SEP-14>grant sysdba to sunny;

Grant succeeded.
再去看看orapworcl的內容,發現多了sunny這個使用者的資訊:
[oracle@localhost dbs]$ strings orapworcl
]\[Z
ORACLE Remote Password file
INTERNAL
6A75B1BBE50E66AB
4DE42795E66117AE
SUNNY
53801465943A91BE
也可以透過動態效能檢視v$pwfile_users檢視有哪些使用者是擁有sysdba許可權的:
SYS@orcl 11-SEP-14>select * from v$pwfile_users;


USERNAME                       SYSDB SYSOP SYSAS
------------------------------ ----- ----- -----
SYS                            TRUE  TRUE  FALSE
SUNNY                          TRUE  FALSE FALSE





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

相關文章