關于 SQLNET.AUTHENTICATION_SERVICES 驗證方式的說明
來源:程序員人生 發布時間:2014-09-08 15:18:42 閱讀次數:3531次
今天去客戶那里巡檢,客戶提出為了提高數據庫安全性考慮,需要修改sys/system密碼,并通過數據庫驗證方式來取代默認的操作系統方式,現在我來把這兩種驗證方式總結一下。
操作系統驗證,即通過操作系統賬戶的權限訪問數據庫,舉個例子,如果已經擁有了windows下的系統管理員administrator的權限,那么當采用該方式驗證的話,無需輸入用戶/密碼就可以訪問,比如:sqlplus / as sysdba;哪怕是任意輸入的用戶名和密碼,也無所謂,比如:sqlplus abc/efg as sysdba;
C:Documents and SettingsAdministrator>sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 8月 28 21:02:25 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> exit
從 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options 斷開
C:Documents and SettingsAdministrator>sqlplus abc/efg as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 8月 28 21:02:33 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
當然,這僅限于sys用戶,對于其他用戶,哪怕是system,也是必須輸入用戶名和密碼才能訪問數據庫的
C:Documents and SettingsAdministrator>sqlplus system/123456
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 8月 28 21:05:07 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-01017: 用戶名/口令無效; 登錄被拒絕
請輸入用戶名:
我的環境中,默認sys和system用戶的密碼都是"oracle",數據庫sys用戶的密碼,是存放在PWD<SID>.ora中的(Unix/Linux中為oraPW<SID>),想知道sys用戶是否有密碼,可以通過以下語句查詢:
SQL> select * from v$pwfile_users;
USERNAME SYSDB SYSOP
------------------------------ ----- -----
SYS TRUE TRUE
顯然,對于采用操作系統驗證來訪問數據庫,安全性還是有一定隱患的,通常在大公司,SA和DBA都是分權管理的,如果數據庫因為采用了操作系統驗證方式,而使SA可以隨意訪問數據庫那也是不太合適的。基于這種場景,那么我們就可以采用數據庫驗證方式來限制sys用戶必須輸入正確的用戶名和密碼才能夠訪問數據庫。這樣的話,當SA沒有DBA的sys密碼,就無法訪問數據庫了。
在windows中,是通過sqlnet.ora這個文件來實現驗證機制控制的,當你裝完數據庫并用netca創建了監聽,就會生成這個文件,通常默認是以下內容:
# This file is actually generated by netca. But if customers choose to
# install "Software Only", this file won't exist and without the native
# authentication, they will not be able to connect to the database on NT.
SQLNET.AUTHENTICATION_SERVICES = (NTS)
也就是說,默認就是采用操作系統驗證的,也許Oracle認為,擁有了SA權限,就擁有了系統最高權限,所以數據庫DBA的sys用戶也無需再驗證密碼了
如果設置成(NONE),就表示采用數據庫身份驗證,還可以設置成(NONE,NTS),其實這樣設也沒有意義了,只要括號中有NTS,就會采用操作系統驗證,NONE就沒有用了
這里要指出一點,有些文章中說還可以設置成(ALL),但我設計測試下來,如果設置成(ALL),會提示ERROR:
C:Documents and SettingsAdministrator>sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 8月 28 21:26:06 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-12641: 驗證服務無法初始化
請輸入用戶名:
如,以下這段描述:
Use the parameter SQLNET.AUTHENTICATION_SERVICES to enable one or more authentication services.
If authentication has been installed,it is recommended that this parameter be set to either none or to one of the authentication methods.
NONE for no authentication methods. A valid username and password can be used to access the database.
ALL for all authentication methods
NTS for Windows NT native authentication(An authentication method that enables
a client single login access to a Windows NT server and a database running on the server)
雖然這里說到了有ALL,不過我親自測試過,確實不行,也許和版本有關,我的版本是10.2.0.1 windows 32bit的
--修改為(NONE)后登陸
C:Documents and SettingsAdministrator>sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 8月 28 21:50:49 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
ERROR:
ORA-01031: 權限不足
請輸入用戶名: sys as sysdba
輸入口令: --此處輸入正確的密碼“oracle”
連接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
--斷開連接,把(NONE)改為(NTS)直接連接
SQL> disc
從 Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options 斷開
SQL> conn abc/123 as sysdba
ERROR:
ORA-01031: 權限不足
由于沒有退出SQLPLUS,剛才改的(NTS)還未生效,可見sqlnet.ora文件是在進入SQLPLUS時才去讀取的
--仍然保持(NTS),退出SQLPLUS后重新登陸
SQL> exit
C:Documents and SettingsAdministrator>sqlplus / as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on 星期四 8月 28 21:54:52 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
現在又是操作系統驗證了
注意,如果改成(NONE)以后,當使用RMAN時,system用戶就不能操作了,輸入正確的密碼也不行,只有sys用戶并輸入密碼才可以,測試如下:
--設置為(NTS)的時候登陸RMAN
C:Documents and SettingsAdministrator>rman target /
恢復管理器: Release 10.2.0.1.0 - Production on 星期四 8月 28 22:02:07 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到目標數據庫: ORCL10G (DBID=1041171248)
RMAN> exit
恢復管理器完成。
C:Documents and SettingsAdministrator>rman target system/oracle
恢復管理器: Release 10.2.0.1.0 - Production on 星期四 8月 28 22:02:33 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到目標數據庫: ORCL10G (DBID=1041171248)
RMAN> exit
恢復管理器完成。
--修改為(NONE)后,再用密碼登陸一次RMAN
C:Documents and SettingsAdministrator>rman target system/oracle
--注意,這里密碼是正確的
恢復管理器: Release 10.2.0.1.0 - Production on 星期四 8月 28 22:03:06 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: 內部恢復管理器程序包初始化失敗
RMAN-04005: 目標數據庫中存在錯誤:
ORA-01031: 權限不足
C:Documents and SettingsAdministrator>rman target /
恢復管理器: Release 10.2.0.1.0 - Production on 星期四 8月 28 22:08:47 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
RMAN-00571: ===========================================================
RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
RMAN-00571: ===========================================================
RMAN-00554: 內部恢復管理器程序包初始化失敗
RMAN-04005: 目標數據庫中存在錯誤:
ORA-01031: 權限不足
C:Documents and SettingsAdministrator>rman target sys/oracle
恢復管理器: Release 10.2.0.1.0 - Production on 星期四 8月 28 22:03:16 2014
Copyright (c) 1982, 2005, Oracle. All rights reserved.
連接到目標數據庫: ORCL10G (DBID=1041171248)
RMAN>
很顯然,在采用數據庫身份驗證以后,system用戶被禁止使用RMAN了,只有擁有數據庫最高權限的sys用戶,才能登陸RMAN,而且必須是輸入密碼的方式登陸
總結:
在windows下,SQLNET.AUTHENTICATION_SERVICES必須設置為NTS才能使用OS認證,不設置(如,把該行語句加#注釋符號)或者設置為其他任何值都不能使用OS認證。
主要是以下幾種情況:
1. sqlnet.ora文件為空,或用#注釋掉 --基于Oracle密碼文件驗證
2. SQLNET.AUTHENTICATION_SERVICES = (NTS) --基于操作系統驗證
3. SQLNET.AUTHENTICATION_SERVICES = (NONE) --基于Oracle密碼文件驗證
4. SQLNET.AUTHENTICATION_SERVICES = (NONE,NTS) --基于操作系統驗證(前后順序顛倒也一樣)
注意:默認情況下,Unix/Linux下的sqlnet.ora文件是沒有SQLNET.AUTHENTICATION_SERVICES參數的,似乎連sqlnet.ora這個文件也沒有,這和windows有很大的不同
此時是操作系統驗證和Oracle密碼驗證并存,如果加上SQLNET.AUTHENTICATION_SERVICES這個參數后,不管是設置為(NONE)、(NTS)或(NONE,NTS),都是基于Oracle密碼驗證。
生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈