Oracle密码文件学习心得

创建Oracle密码文件的命令

orapwd file=<> password=<> entries=最大数目

这里的file命名规则在unix/linux下 orapw<ORACLE_SID>,在windows下为 pwd<SID>.ora

具体资料看下面的描述(这是pub中一个网友的总结)

1. unix 环境:

查了Administrator‘s Reference 10g Release 2 (10.2) for UNIX-Based Operating Systems.

1. Log in as the Oracle software owner. (以Oracle管理员身份登入)

2. Use the orapwd utility to create the password file as follows(使用orapwd功能创建密码文件):

$ $ORACLE_HOME/bin/orapwd file=filename password=password entries=max_users……

filename The name of the file in which password information is written(filename指密码信息保存文件的文件名)

The name of the file must be orapwsid, and you must supply the full path name. Its contents are encrypted. Typically, the password file is created in the $ORACLE_HOME/dbs directory.(文件名必须为orapwsid,并需要提供完整路径。内容是加密的。通常情况下,密码文件被创建在$ORACLE_HOME/dbs路径下。)

请注意黑体字, 所以unix环境中, password file 一定是要用 orapw<SID>, 没有例外。

2. windows 环境:

查了Platform. Guide 10g Release 2 (10.2) for Microsoft Windows (32-Bit) (没查64-bit)

To create and populate a password file:

(1). Create a password file with the Password Utility:

C:> orapwd FILE=PWDsid.ora PASSWORD=password ENTRIES=max_users

where

| FILE specifies the password filename.

| SID identifies the database instance.

| PASSWORD sets the password for account SYS.

| ENTRIES sets maximum number of entries in password file. This corresponds to maximum number of distinct users allowed to connect to the database simultaneously with either the SYSDBA or the SYSOPER DBA privilege.

(2). Set initialization parameter file parameter REMOTE_LOGIN_PASSWORDFILE to exclusive, shared, or none.

In search of the password file, Oracle Database looks in the registry for the value of parameter

ORA_SID_PWFILE. If no value is specified, then it looks in the registry for the

value of parameter ORA_PWFILE, which points to a file containing usernames,

passwords, and privileges. If that is not set, then it uses the default:

ORACLE_BASEORACLE_HOMEDATABASEPWDsid.ORA.

The default value is shared.

请注意黑体字, windows 环境中, 很大的部分是基于 registry 中变量 ora_sid_pwfile 或者 ora_pwfile 的设置, 缺省的值, 正如paulyibinyi兄弟指出的, 是 pwd<SID>.ora (unix中是没有这个。ora后缀的)。

二、在windows下对于connect /as sysdba及其它用户可以不用密码就能登录的问题

1.这是因为oracle采用了 OS认证的方式,具体的可以查看 sqlnet.ora具体同容如下

SQLNET.AUTHENTICATION_SERVICES= (NTS)

将其改成SQLNET.AUTHENTICATION_SERVICES= (NONE)

这样就是oracle认证方式了

2.因为用的OS认证方式,可以在操作系统->控制面版->计算机管理->用户 将当前用户的属性组 ORA_DBA去掉,这时如果没有用户名及密码则不可以。

如下:

SQL> connect /as sysdba ERROR:ORA-01031: insufficient privileges

SQL> connect sys/oracle as sysdba

已连接。

三、利用alter user identified by ……来修改密码alter user sys identified by abc一下,就连数据库中的密码和密码文件中的密码一起改成abc了;

四、如果Oracle密码文件丢失了如何办?

利用 orapwd重新创建一个就可以了。

文章来源:网络 编辑:联动北方技术论坛

(如有侵权请及时联络以便删除)

 

第二篇:Oracle密码文件

密码文件(password file)是一个可选的文件,允许远程 SYSDBA 或管理员访问数据库。

启动 Oracle 时,还没有数据库可以用来验证密码。在“本地”系统上启动 Oracle 时(也就是说,不 在网络上,而是从数据库实例所在的机器启动),Oracle 会利用操作系统来执行这种认证。

安装 Oracle 时,会要求完成安装的人指定管理员“组”。在 UNIX/Linux 上,这个组一般默认为 DBA, 在 Windows 上则默认为 OSDBA。不过,也可以是平台上任何合法的组名。这个组很“特殊”,因为这个组中 的任何用户都可以作为 SYSDBA 连接 Oracle ,而无需 指定 用户 名或 密码 。例如,在安装 Oracle 10g Release1 时,我指定了一个 ora10g 组。ora10g 组中的任何用户都无需用户名/密码就能连接:

[ora10g@localhost ora10g]$ sqlplus / as sysdba

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:13:04 2005

Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to:

Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL> show user

USER is "SYS"

这是可以的——我就成功地连接了 Oracle,现在我能启动这个数据库,将其关闭,或者完成我想做的任何管理工作。不过,假设我想从另外一台机器通过网络完成这些操作,会怎么样呢?在这种情况下, 我试图使用@tns-connect-string 来连接。不过这会失败:

[ora10g@localhost admin]$ sqlplus /@ora10g_admin.localdomain as sysdba

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:14:20 2005

Copyright (c) 1982, 2004, Oracle. All rights reserved. ERROR:

ORA-01031: insufficient privileges

Enter user-name:

在网络上,对于 SYSDBA 的操作系统认证不再奏效,即使把很不安全的 REMOTE_ OS_AUTHENT 参数设置为 TRUE 也 不例外。所以,操作系统认证不可行。如前所述,如果你想启动一个实例进行装载,并打开一 个数据库,根据定义,在连接的另一端实际上“还没有数据库”,也无 法从中查找认证的详细信息。这就 是一个鸡生蛋还是蛋生鸡的问题。因此密码文件“应运而生”。密码文件保存了一个用户名和密码列表,这 些用户名和密码分别对 应于可以通过网络远程认证为 SYSDBA 的用户。Oracle 必须使用这个文件来认证用 户,而不是数据库中存储的正常密码列表。

下面校正这种情况。首先,我们要本地启动数据库,以便设置 REMOTE_LOGIN_PASSWORDFILE。其默认 值为 NONE,这意味着没有密码文件;不存在“远程 SYSDBA 登录”。这个参数还有另外两个设置:SHARED(多 个数据库可以使用同样的密码文件)和 EXCLUSIVE(只有一个数据库使用一个给定的密码文件)。这里设置 为 EXCLUSIVE,因为我们只想对一个数据库使用这个密码文件(这也是一般用法):

SQL> alter system set remote_login_passwordfile=exclusive scope=spfile;

System altered.

实例启动和运行时,这个设置不能动态改变,所以要想让它生效必须重启实例。下一步是使用命令行工具(UNIX 和 Windows 平台上)orapwd 创建和填写这个初始的密码文件:

[ora10g@localhost dbs]$ orapwd

Usage: orapwd file=<fname> password=<password> entries=<users> force=<y/n>

在此: file——密 码文 件名 (必 要)。 password——SYS 的 密码 (必 要)。entries——DBA 和操作员的最大数目(可选)。 force——是否重写现有的文件(可选)。 等号(=)两边没有空格。

我们使用的命令为:

$ orapwd file=orapw$ORACLE_SID password=bar entries=20

对我来说,这样会创建一个名为 orapwora10g 的密码文件(我的 ORACLE_SID 是 ora10g)。

这是大多数 UNIX 平台上密码文件的命名约定(有关各平台上密码文件的命名,详细内容请参见你的 安装 / 操作 系 统 管 理 员 指 南 ),这 个 文 件 位 于 $ORACLE_HOME/dbs 目录 中 。 在 Windows 上, 文 件 名 为 PW%ORACLE_SID%.ora,在%ORACLE_HOME%database 目录中。

目前该文件中只有一个用户,也就是用户 SYS,尽管数据库上还有其他 SYSDBA 账户,但它们还不在 密码文件中。不过,基于以上设置,我们可以第一次作为 SYSDBA 通过网络连接 Oracle:

[ora10g@localhost dbs]$ sqlplus sys/bar@ora10g_admin.localdomain as sysdba

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:49:15 2005

Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to an idle instance. SQL>

我们通过了认证,所以登录成功,现在可以使用 SYSDBA 账户成功地启动、关闭和远程管

理这个数据库了。下面,再看另一个用户 OPS$TKYTE,它已经是一个 SYSDBA 账户(已经授予 SYSDBA),但是还 不能 远 程连接:

[ora10g@localhost dbs]$ sqlplus 'ops$tkyte/foo' as sysdba

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:51:07 2005

Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to:

Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL> show user

USER is "SYS" SQL> exit

[ora10g@localhost dbs]$ sqlplus 'ops$tkyte/foo@ora10g_admin.localdomain' as sysdba

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:52:57 2005

Copyright (c) 1982, 2004, Oracle. All rights reserved. ERROR:

ORA-01031: insufficient privileges

Enter user-name:

原因是,OPS$TKYTE 还不在密码文件中。要把 OPS$TKYTE 放到密码文件中,需要重新对该账户授予SYSDBA:

SQL> grant sysdba to ops$tkyte;

Grant succeeded.

Disconnected from Oracle Database 10g

Enterprise Edition Release 10.1.0.3.0 - Production

With the Partitioning, OLAP and Data Mining options

[ora10g@localhost dbs]$ sqlplus 'ops$tkyte/foo@ora10g_admin.localdomain' as sysdba

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:57:04 2005

Copyright (c) 1982, 2004, Oracle. All rights reserved. Connected to:

Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production

With the Partitioning, OLAP and Data Mining options

这样会在密码文件中创建一个条目,Oracle 现在会保持密码“同步”。如果 OPS$TKYTE 修改了他的密码,原来的密码将无法完成远程 SYSDBA 连接,新密码才能启动 SYSDBA 连接:

SQL> alter user ops$tkyte identified by bar;

User altered.

[ora10g@localhost dbs]$ sqlplus 'ops$tkyte/foo@ora10g_admin.localdomain' as sysdba

SQL*Plus: Release 10.1.0.3.0 - Production on Sun Jan 2 20:58:36 2005

Copyright (c) 1982, 2004, Oracle. All rights reserved. ERROR:

ORA-01017: invalid username/password; logon denied

Enter user-name: ops$tkyte/bar@ora10g_admin.localdomain as sysdba

Connected to:

Oracle Database 10g Enterprise Edition Release 10.1.0.3.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL> show user

USER is "SYS" SQL>

对于其他不在密码文件中的 SYSDBA 用户,再重复同样的过程。

【元鼎时代原创内容,版权所有】

相关推荐