oracle本地验证和密码文件有什么作用

44次阅读
没有评论

共计 4271 个字符,预计需要花费 11 分钟才能阅读完成。

这篇文章主要介绍“oracle 本地验证和密码文件有什么作用”,在日常操作中,相信很多人在 oracle 本地验证和密码文件有什么作用问题上存在疑惑,丸趣 TV 小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”oracle 本地验证和密码文件有什么作用”的疑惑有所帮助!接下来,请跟着丸趣 TV 小编一起来学习吧!

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

到此,关于“oracle 本地验证和密码文件有什么作用”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注丸趣 TV 网站,丸趣 TV 小编会继续努力为大家带来更多实用的文章!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-20发表,共计4271字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)