广告
返回顶部
首页 > 资讯 > 数据库 >Oracle中两种认证方式:OS认证与口令文件认证
  • 493
分享到

Oracle中两种认证方式:OS认证与口令文件认证

2024-04-02 19:04:59 493人浏览 薄情痞子
摘要

相关链接:SYS,SYSTEM,DBA,SYSDBA,SYSOPER的区别与联系    首先谈谈oracle安装与OS用户组.Oracle在安装和维护过程


相关链接:SYS,SYSTEM,DBA,SYSDBA,SYSOPER的区别与联系 

 

首先谈谈oracle安装与OS用户组.Oracle在安装和维护过程中经常要和操作用户组(OS User Group)打交道,从早前的只有oracle用户和dba组发展到今天11gR2中的grid用户和asm组。

我们在单实例环境中常用的三个操作用户组,分别是:

 

1oinstall用户组

oinstall组是Oracle推荐创建的OS用户组之一,建议在系统第一次安装Oracle产品之前创建oinstall组,理论上该oinstall组应当拥有Oracle软件产品目录(例如$CRS_HOME和$ORACLE_HOME)和oracle Inventory信息目录仓库,oracle Inventory信息目录记录了系统上安装过的Oracle产品的记录。

若系统中已有安装过Oracle产品软件,则现有的oracle Inventory目录的所有组必须是今后用来安装新oracle软件产品的用户的主组。

现有的oracle Inventory拥有者组可以通过/etc/orainst.loc位置文件了解:

inventory_loc=/u01/app/oracle/oraInventory
inst_group=oinstall

若/etc/oraInst.loc位置文件不存在,那么建议创建oinstall用户组,注意在RAC环境中要保持各节点上用户组的GID一致:

# /usr/sbin/groupadd -g GID oinstall

 

2OSDBA用户组(dba)

OSDBA是我们必须要创建的一种系统DBA用户组(dba),若没有该用户组我们将无法安装数据库软件及执行管理数据库的任务。

 

3OSOPER用户组(oper)

OSOPER是一种额外的用户组(oper),我们可以选择要不要创建该用户组,创建该用户组可以满足让os用户行使某些数据库管理权限(包括SYSOPER角色权限)的目的。

 

创建OSOPER用户组的方法:

# /usr/sbin/groupadd oper

综上所述在单实例环境中Oracle拥有者用户(常用的是oracle),因该同时是oinstall、dba、oper用户组的成员。同时该用户的主用户组必须是oinstall。

 

而在11.2的GI/CRS环境中数据库软件拥有者用户(oracle)还必须是asmdba用户组的成员。

usermod -g oinstall -G dba,oper,asmdba oracle
id oracle
uid=54321(oracle) gid=54321(oinstall)
groups=54321(oinstall),54322(dba),701(asmdba),54324(oper)

 

注意OSDBA和OSOPER用户组都受到$ORACLE_HOME/rdbms/lib/config.c 源文件的影响,该文件定义了默认的 SS_DBA_GRP “dba” 和SS_OPER_GRP “oper”,该源文件内容如下:

 




#define SS_DBA_GRP "dba"
#define SS_OPER_GRP "oper"
#define SS_ASM_GRP ""
char *ss_dba_grp[] = {SS_DBA_GRP, SS_OPER_GRP, SS_ASM_GRP}; 

 

char *ss_dba_grp[] = {SS_DBA_GRP, SS_OPER_GRP, SS_ASM_GRP}; Oracle11g Release2中oracle建议独立地管理Grid Infrastructure和ASM实例,因此有必要创建更多的os用户组以满足不同的权限分配。

我们在11.2的GI中常用的ASM用户组有以下三个:

 

1OSASM(asmadmin)用户组

如果使用ASM,那么我们必须创建osasm(asmadmin)用户组,该OSASM用户组的成员将被赋予SYSASM权限,以满足组成员管理Oracle Clusterware和Oracle ASM的权限需求。

 

2OSDBA for ASM group(asmdba)用户组

OSDBA(asmdba)用户组的成员将被赋予读写访问ASM文件的权限。GI/CRS拥有者用户和所有oracle数据库软件的拥有者必须是该组的成员。同时所有OSDBA(dba)用户组的成员也必须是asmdba组的成员。

 

3OSOPER for ASM(asmoper)用户组

asmoper和osoper类似都是额外的可选择创建的用户组,创建该独立的用户组以满足赋予用户一套受限的ASM实例管理权限(ASM的SYSOPER角色),该权限包括了启动和停止ASM实例,默认情况下OSASM(asmadmin)组成员将拥有所有SYSOPER的ASM管理权限。

在11.2的GI/CRS环境中一般会创建grid或griduser用户来管理GI软件和ASM实例,以如下方式创建grid用户:

useradd -g oinstall -G asmadmin,asmdba,asmoper grid 
id grid
uid=54322(grid) gid=54321(oinstall)
groups=54321(oinstall),700(asmadmin),701(asmdba),55000(asmoper)

 

在Oracle中有两类特殊的权限SYSDBA和SYSOPER,当DBA需要对数据库进行维护管理操作的时候必须具有这两类特殊权限之中的一种。在数据库没有打开的时候,使用数据库内建的账号是无法登陆数据库的,但是拥有SYSDBA或是SYSOPER权限的用户是可以登陆的。认证用户是否拥有两类特殊权限的方法有两种:OS认证和口令文件认证。

Oracle数据库究竟使用OS认证还是口令文件认证来进行管理取决于下面三个因素:

1、sqlNET.ORA参数文件中的参数SQLNET.AUTHENTICATioN_SERVICES设置

2、PFILE(SPFILE)参数文件中的参数REMOTE_LOGIN_PASSWordFILE设置

3、口令文件orapw$SID(linux) | PWD$SID.ora(windows)

Oracle权限认证的基本顺序是这样的,先由SQLNET.AUTHENTICATION_SERVICES的设置值来决定是使用OS认证还是口令文件认证,如果使用口令文件认证的话就要看后面两个条件了:如果REMOTE_LOGIN_PASSWORDFILE参数设置为非NONE而且口令文件存在的话就能正常使用口令文件认证,否则将会失败。

 

SQLNET.AUTHENTICATION_SERVICES参数

在SQLNET.ORA(位于$ORACLE_HOME/NETWORK/ADMIN目录中)文件中,需要修改时直接用文本编辑器打开修改就行了,对于不同的操作系统SQLNET.AUTHENTICATION_SERVICES的取值会有些不一样,通常我们会用到下面的一些设置值:

  • SQLNET.AUTHENTICATION_SERVICES = (ALL)

对Linux系统,支持OS认证和口令文件认证。

对Windows系统,实际实验是不支持此参数,验证失败。

  • SQLNET.AUTHENTICATION_SERVICES = (NTS)

此设置值仅用于Windows系统,此设置同时支持OS认证和口令文件认证,只有在设置了(NTS)值之后运行在Windows系统上的Oracle才支持OS认证。

  • SQLNET.AUTHENTICATION_SERVICES = (NONE)

此设置值在Windows和Linux是作用一样的,指定Oracle只使用口令文件认证。

  • 不设置此参数或SQLNET.AUTHENTICATION_SERVICES =

对Linux系统,默认支持OS认证和口令文件认证。

对Windows系统,默认只支持口令文件认证,不支持OS认证。

 

OS认证实现

Oracle使用操作系统中的两个用户组来控制OS认证,在不同的操作系统中这两个用户组的名称是不一样的,一般来说他们是OSDBA 和 OSOPER,这两个用户组都是在Oracle安装的时候创建的。下面列出不同系统中这两个用户组的名字:

Operating System Group

UNIX User Group

UNIX User Group

OSDBA

dba

ORA_DBA

OSOPER

oper

ORA_OPER

OSDBA用户组的用户可以使用SYSDBA权限登陆数据库,OSOPER用户组的的用户可以使用SYSOPER权限来登陆数据库。使用sqlplus可以用下面方法登陆

CONNECT / AS SYSDBA 
CONNECT / AS SYSOPER

拥有OS权限的用户登陆数据库时不再需要输入用户名和密码,因此使用下面的命令也是可以正常登陆的:

CONNECT ANY_USER_NAME/ANY_PASSWORD AS SYSDBA 
CONNECT ANY_USER_NAME/ANY_PASSWORD AS SYSOPER

因此要创建一个新的OS认证帐号步骤是:

  1. 建立一个OS用户
  2. 将用户加入到OSDBA或是OSOPER用户组
  3. 用新增加的用户登陆系统,然后输入sqlplus / AS SYSDBA进行登陆

 

REMOTE_LOGIN_PASSWORDFILE参数

REMOTE_LOGIN_PASSWORDFILE系统参数的设置制定了数据库使用口令文件的方法,此参数可以设置的值有三个:

  • REMOTE_LOGIN_PASSWORDFILE = NONE

不使用口令文件

  • REMOTE_LOGIN_PASSWORDFILE = EXCLUSIVE

使用口令文件,但只有一个数据库实例可用使用

  • REMOTE_LOGIN_PASSWORDFILE = SHARED

多个数据库实例共用一个口令文件,这种设置下是不能增加其他数据库用户作为特殊权限用户到口令文件中的。

REMOTE_LOGIN_PASSWORDFILE参数属于初始化参数,只能在init.ora/pfile中指定或是在数据库打开状态下使用下面语句修改,然后重新启动数据库。

ALTER SYSTEM SET REMOTE_LOGIN_PASSWORDFILE = EXCLUSIVE SCOPE = SPFILE ;

要检查当前REMOTE_LOGIN_PASSWORDFILE的设定值在登陆Oracle后输入下面的命令


SYS@seiang11g>show parameter remote

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

remote_dependencies_mode             string      TIMESTAMP

remote_listener                      string

remote_login_passwordfile            string      EXCLUSIVE

remote_os_authent                    boolean     FALSE

remote_os_roles                      boolean     FALSE

result_cache_remote_expiration       integer     0

 

 

 

下面是11g官方文档的解释:

*******************************************************************************

Selecting an Authentication Method for Database Administrators

Database Administrators can authenticate database administrators through the data dictionary, (using an account password) like other users. Keep in mind that beginning with Oracle Database 11g Release 1, database passwords are case-sensitive. (You can disable case sensitivity and return to pre–Release 11gbehavior by setting the SEC_CASE_SENSITIVE_LOGoN initialization parameter to FALSE.)

数据库管理员可以通过数据字典(使用帐户密码)与其他用户进行身份验证数据库管理员。 请记住,从Oracle Database 11g1版开始,数据库密码区分大小写。(可以通过将SEC_CASE_SENSITIVE_LOGON初始化参数设置为FALSE来禁用区分大小)

 

In addition to nORMal data dictionary authentication, the following methods are available for authenticating database administrators with the SYSDBA or SYSOPERprivilege:

除了正常的数据字典认证之外,以下方法可用于使用SYSDBASYSOPER权限对数据库管理员进行身份验证

  • Operating system (OS) authentication
  • Password files
  • Strong authentication with a network-based authentication service, such as Oracle Internet Directory

 

These methods are required to authenticate a database administrator when the database is not started or otherwise unavailable. (They can also be used when the database is available.)

当数据库未启动或不可用时,需要这些方法来对数据库管理员进行身份验证。(当数据库可用时也可以使用它们。)

 

Notes:

·         These methods replace the CONNECT INTERNAL syntax provided with earlier versions of Oracle Database. CONNECT INTERNAL is no longer supported.

·         Operating system authentication takes precedence over password file authentication. If you meet the requirements for operating system authentication, then even if you use a password file, you will be authenticated by operating system authentication.

Your choice will be influenced by whether you intend to administer your database locally on the same system where the database resides, or whether you intend to administer many different databases from a single remote client. Figure 1-2 illustrates the choices you have for database administrator authentication schemes.

Figure 1-2 Database Administrator Authentication Methods


If you are performing remote database administration, consult your Oracle Net documentation to determine whether you are using a secure connection. Most popular connection protocols, such as tcp/IP and DECnet, are not secure.

 

Nonsecure Remote Connections

To connect to Oracle Database as a privileged user over a nonsecure connection, you must be authenticated by a password file. When using password file authentication, the database uses a password file to keep track of database user names that have been granted the SYSDBA or SYSOPER system privilege. This form of authentication is discussed in "Using Password File Authentication".

要通过非安全连接作为特权用户连接到Oracle数据库,必须通过密码文件进行身份验证。 使用密码文件认证时,数据库使用密码文件来跟踪已被授予SYSDBASYSOPER系统权限的数据库用户名。

Local Connections and Secure Remote Connections

You can connect to Oracle Database as a privileged user over a local connection or a secure remote connection in two ways:

  • If the database has a password file and you have been granted the SYSDBA or SYSOPER system privilege, then you can connect and be authenticated by a password file.

如果数据库具有密码文件,并且您已被授予SYSDBASYSOPER系统权限,则可以通过密码文件进行连接和身份验证。

 

  • If the server is not using a password file, or if you have not been granted SYSDBA or SYSOPER privileges and are therefore not in the password file, you can use operating system authentication. On most operating systems, authentication for database administrators involves placing the operating system username of the database administrator in a special group, generically referred to as OSDBA. Users in that group are granted SYSDBA privileges. A similar group, OSOPER, is used to grant SYSOPER privileges to users.

如果服务器未使用密码文件,或者尚未授予SYSDBASYSOPER权限,因此不在密码文件中,则可以使用操作系统身份验证。 在大多数操作系统上,数据库管理员的身份验证包括将数据库管理员的操作系统用户名放在一个特殊的组中,一般称为OSDBA 该组中的用户被授予SYSDBA权限。 类似的组OSOPER用于向用户授予SYSOPER权限。

Using Operating System Authentication

This section describes how to authenticate an administrator using the operating system.

OSDBA and OSOPER

Membership in one of two special operating system groups enables a DBA to authenticate to the database through the operating system rather than with a database user name and password. This is known as operating system authentication. These operating system groups are generically referred to as OSDBA and OSOPER. The groups are created and assigned specific names as part of the database installation process. The default names vary depending upon your operating system, and are listed in the following table:

Operating System Group

UNIX User Group

Windows User Group

OSDBA

dba

ORA_DBA

OSOPER

oper

ORA_OPER

在两个特殊操作系统组之一中的成员使DBA能够通过操作系统而不是使用数据库用户名和密码对数据库进行身份验证, 这被称为操作系统认证。

Oracle Universal Installer uses these default names, but you can override them. One reason to override them is if you have multiple instances running on the same host computer. If each instance is to have a different person as the principal DBA, you can improve the security of each instance by creating a different OSDBA group for each instance. For example, for two instances on the same host, the OSDBA group for the first instance could be named dba1, and OSDBA for the second instance could be named dba2. The first DBA would be a member of dba1 only, and the second DBA would be a member of dba2 only. Thus, when using operating system authentication, each DBA would be able to connect only to his assigned instance.

Oracle Universal Installer使用默认名称,但你可以覆盖它们。 覆盖它们的一个原因是如果您有多个实例运行在同一主机上。 如果每个实例都要有一个不同的人作为DBA,则可以通过为每个实例创建一个不同的OSDBA组来提高每个实例的安全性。 例如,对于同一主机上的两个实例,第一个实例的OSDBA组可以命名为dba1,第二个实例的OSDBA组可以命名为dba2 第一个DBA只是dba1的成员,第二个DBA只是dba2的成员。 因此,当使用操作系统认证时,每个DBA将只能连接到他分配的实例。

Membership in the OSDBA or OSOPER group affects your connection to the database in the following ways:

  • If you are a member of the OSDBA group and you specify AS SYSDBA when you connect to the database, then you connect to the database with theSYSDBA system privilege.
  • If you are a member of the OSOPER group and you specify AS SYSOPER when you connect to the database, then you connect to the database with theSYSOPER system privilege.
  • If you are not a member of either of these operating system groups and you attempt to connect as SYSDBA or SYSOPER, the CONNECT command fails.

 

Preparing to Use Operating System Authentication

To enable operating system authentication of an administrative user:

  1. Create an operating system account for the user.
  2. Add the account to the OSDBA or OSOPER operating system defined groups.

Connecting Using Operating System Authentication

A user can be authenticated, enabled as an administrative user, and connected to a local database by typing one of the following SQL*Plus commands:

CONNECT / AS SYSDBA
CONNECT / AS SYSOPER

For the Windows platform only, remote operating system authentication over a secure connection is supported. You must specify the net service name for the remote database:

CONNECT /@net_service_name AS SYSDBA
CONNECT /@net_service_name AS SYSOPER

Both the client computer and database host computer must be on a Windows domain.

 

口令文件存放着被授予SYSDBA或SYSOPER权限的用户的用户名和密码。它是一个加密的文件,用户不能修改这个文件,在Linux系统中口令文件一般保存在$ORACLE_HOME/dbs目录下,文件名为orapw$SID;在Windows系统中口令文件一般保存在$ORACLE_HOME/database目录下,文件名为PWD$SID.ora。

使用口令文件认证的基本步骤是:

  1. 使用orapwd工具生成口令文件
  2. 设置REMOTE_LOGIN_PASSWORDFILE为EXCLUSIVE或是SHARED
  3. 使用SYS登陆数据库,创建新的数据库用户
  4. 使用GRANT命令授予新创建的用户SYSDBA/SYSOPER权限

 

Using Password File Authentication

This section describes how to authenticate an administrative user using password file authentication.

Preparing to Use Password File Authentication

To enable authentication of an administrative user using password file authentication you must do the following:

  1. If not already created, create the password file using the ORAPWD utility:

2.    ORAPWD FILE=filename ENTRIES=max_users

See "Creating and Maintaining a Password File" for details
Notes:

o    When you invoke Database Configuration Assistant (DBCA) as part of the Oracle Database installation process, DBCA creates a password file.

o    Beginning with Oracle Database 11g Release 1, passwords in the password file are case-sensitive unless you include the IGNORECASE = Y command-line argument.

Oracle Database 11g1版开始,密码文件中的密码区分大小写,除非您包含IGNORECASE = Y命令行参数。

  1. Set the REMOTE_LOGIN_PASSWORDFILE initialization parameter to EXCLUSIVE. (This is the default).

Note:

REMOTE_LOGIN_PASSWORDFILE is a static initialization parameter and therefore cannot be changed without restarting the database.

  1. Connect to the database as user SYS (or as another user with the administrative privileges).
  2. If the user does not already exist in the database, create the user and assign a password.

Keep in mind that beginning with Oracle Database 11g Release 1, database passwords are case-sensitive. (You can disable case sensitivity and return to pre–Release 11g behavior by setting the SEC_CASE_SENSITIVE_LOGON initialization parameter to FALSE.)

  1. Grant the SYSDBA or SYSOPER system privilege to the user:

7.    GRANT SYSDBA to oe;

This statement adds the user to the password file, thereby enabling connection AS SYSDBA.

 

Connecting Using Password File Authentication

Administrative users can be connected and authenticated to a local or remote database by using the SQL*Plus CONNECT command. They must connect using their username and password and the AS SYSDBA or AS SYSOPER clause. Note that beginning with Oracle Database 11g Release 1, passwords are case-sensitive unless the password file was created with the IGNORECASE = Y option.

For example, user oe has been granted the SYSDBA privilege, so oe can connect as follows:

CONNECT oe AS SYSDBA

However, user oe has not been granted the SYSOPER privilege, so the following command will fail:

CONNECT oe AS SYSOPER

Note:

Operating system authentication takes precedence over password file authentication. Specifically, if you are a member of the OSDBA or OSOPER group for the operating system, and you connect as SYSDBA or SYSOPER, you will be connected with associated administrative privileges regardless of the username/password that you specify.

操作系统认证优先于密码文件认证。 具体来说,如果您是操作系统的OSDBAOSOPER组的成员,并以SYSDBASYSOPER身份连接,则无论您指定的用户名/密码如何,都将连接相关联的管理权限。

 

If you are not in the OSDBA or OSOPER groups, and you are not in the password file, then attempting to connect as SYSDBA or as SYSOPER fails.

如果您不在OSDBAOSOPER组中,并且您不在密码文件中,则尝试以SYSDBASYSOPER身份连接。

 

Creating and Maintaining a Password File

您可能感兴趣的文档:

--结束END--

本文标题: Oracle中两种认证方式:OS认证与口令文件认证

本文链接: https://www.lsjlt.com/news/45348.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作