操作系統驗證,即通過操作系統賬戶的權限訪問數據庫,舉個樣例,假設已經擁有了windows下的系統管理員administrator的權限,那么當採用該方式驗證的話,無需輸入用戶/password就能夠訪問,比方:sqlplus / as sysdba;哪怕是隨意輸入的username和password。也無所謂,比方:sqlplus abc/efg as sysdba;
C:\Documents and Settings\Administrator>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 Settings\Administrator>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,也是必須輸入username和password才干訪問數據庫的
C:\Documents and Settings\Administrator>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: username/口令無效; 登錄被拒絕
請輸入username:
我的環境中。默認sys和system用戶的password都是"oracle",數據庫sys用戶的password,是存放在PWD<SID>.ora中的(Unix/Linux中為oraPW<SID>)。想知道sys用戶是否有password,能夠通過下面語句查詢:
SQL> select * from v$pwfile_users;
USERNAME SYSDB SYSOP
------------------------------ ----- -----
SYS TRUE TRUE
顯然,對於採用操作系統驗證來訪問數據庫,安全性還是有一定隱患的,通常在大公司,SA和DBA都是分權管理的,假設數據庫由於採用了操作系統驗證方式,而使SA能夠任意訪問數據庫那也是不太合適的。基於這種場景。那么我們就能夠採用數據庫驗證方式來限制sys用戶必須輸入正確的username和password才干夠訪問數據庫。這種話,當SA沒有DBA的syspassword。就無法訪問數據庫了。
在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用戶也無需再驗證password了
假設設置成(NONE),就表示採用數據庫身份驗證。還能夠設置成(NONE,NTS),事實上這樣設也沒有意義了,僅僅要括號里有NTS。就會採用操作系統驗證。NONE就沒實用了
C:\Documents and Settings\Administrator>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: 驗證服務無法初始化
請輸入username:
如。下面這段描寫敘述:
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 Settings\Administrator>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: 權限不足
請輸入username: sys as sysdba
輸入口令: --此處輸入正確的password“oracle”
連接到:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>
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 Settings\Administrator>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用戶就不能操作了,輸入正確的password也不行,僅僅有sys用戶並輸入password才干夠。測試例如以下:
--設置為(NTS)的時候登陸RMAN
C:\Documents and Settings\Administrator>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 Settings\Administrator>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)后,再用password登陸一次RMAN
C:\Documents and Settings\Administrator>rman target system/oracle --注意。這里password是正確的
恢復管理器: 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 Settings\Administrator>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 Settings\Administrator>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,並且必須是輸入password的方式登陸
總結:
在windows下。SQLNET.AUTHENTICATION_SERVICES必須設置為NTS才干使用OS認證,不設置(如,把該行語句加#凝視符號)或者設置為其它不論什么值都不能使用OS認證。
主要是下面幾種情況:
1. sqlnet.ora文件為空,或用#凝視掉 --基於Oraclepassword文件驗證
2. SQLNET.AUTHENTICATION_SERVICES = (NTS) --基於操作系統驗證
3. SQLNET.AUTHENTICATION_SERVICES = (NONE) --基於Oraclepassword文件驗證
4. SQLNET.AUTHENTICATION_SERVICES = (NONE,NTS) --基於操作系統驗證(前后順序顛倒也一樣)
注意:默認情況下,Unix/Linux下的sqlnet.ora文件是沒有SQLNET.AUTHENTICATION_SERVICES參數的,似乎連sqlnet.ora這個文件也沒有,這和windows有非常大的不同
此時是操作系統驗證和Oraclepassword驗證並存。假設加上SQLNET.AUTHENTICATION_SERVICES這個參數后,無論是設置為(NONE)、(NTS)或(NONE,NTS),都是基於Oraclepassword驗證。