溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

oracle本地驗證和密碼文件有什么作用

發(fā)布時間:2021-11-11 14:45:06 來源:億速云 閱讀:270 作者:iii 欄目:關系型數據庫

這篇文章主要介紹“oracle本地驗證和密碼文件有什么作用”,在日常操作中,相信很多人在oracle本地驗證和密碼文件有什么作用問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”oracle本地驗證和密碼文件有什么作用”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

oracle的密碼文件作用是進行DBA權限的身份驗證。
當數據庫開啟到mount狀態(tài)時,數據庫必須要具備一個很重要的密碼文件/口令文件,這個文件默認是存放在$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

在數據庫中創(chuàng)建一個新的用戶并授予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的內容,發(fā)現多了sunny這個用戶的信息:
[oracle@localhost dbs]$ strings orapworcl
]\[Z
ORACLE Remote Password file
INTERNAL
6A75B1BBE50E66AB
4DE42795E66117AE
SUNNY
53801465943A91BE

也可以通過動態(tài)性能視圖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

到此,關于“oracle本地驗證和密碼文件有什么作用”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注億速云網站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI